Search code examples
c++qtsignals-slots

signals and slots with a condition


I have a mainwindow.ui with a QLineEdit_1 and secondWindow.ui with multiple QLineEdit widgets , in short, i wanted to make a condition where when entering a certain number in QLineEdit_1 would result in text output on some of the QLineEdit widgets as "null" and the rest would still be blank.

what are the main steps to achieving the above if also anyone would lead me to an example similar that would be great thanks.


Solution

  • Sounds like you are searching for signal-slot-connections: http://doc.qt.io/qt-5/signalsandslots.html.

    In your case listen to textChanged() of QLineEdit_1 and create a slot in e.g. secondWindow.ui-class where you set the other line edits as you like:

    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.
    }