有条件的信号和插槽

时间:2017-04-29 15:36:50

标签: c++ qt signals-slots

我有一个带有QLineEdit_1的mainwindow.ui和带有多个QLineEdit小部件的secondWindow.ui,简而言之,我想提出一个条件,当在QLineEdit_1中输入某个数字时会导致某些QLineEdit小部件上的文本输出为"空"其余的仍然是空白。

实现上述目标的主要步骤是什么? 如果有人也会引导我一个类似的例子,这将是伟大的 感谢。

1 个答案:

答案 0 :(得分:2)

听起来您正在搜索信号插槽连接:http://doc.qt.io/qt-5/signalsandslots.html

在您的情况下,请收听QLineEdit_1的textChanged()并在例如secondWindow.ui-class,您可以根据需要设置其他行编辑:

connect(QLineEdit_1, &QLineEdit::textChanged, 
        PointerToSecondWindow, &secondWindow::yourSlot);

// In secondWindow.cpp
void secondWindow::yourSlot(const QString &text) {
    // Do with text whatever you like and set the
    // other line edits.
}
相关问题