"Group Signal" to be emmited



  • Suppose I have numerous spinbox widgets, say 10 input widgets. I then have 1 output widget.
    How do I write the signal slot connect code to make the output widget change after ANY of the input widgets are finished editing?

    So for example, for 1 specific signal, the code would be:
    @ connect (ui ->doubleSpinBox, SIGNAL (editingFinished()),this, SLOT (mySlot()));@

    Now I could do this for every input widget, like so:
    @ connect (ui ->doubleSpinBox, SIGNAL (editingFinished()),this, SLOT (mySlot()));@
    @ connect (ui ->doubleSpinBox_2, SIGNAL (editingFinished()),this, SLOT (mySlot()));@
    @ connect (ui ->doubleSpinBox_3, SIGNAL (editingFinished()),this, SLOT (mySlot()));@
    @ connect (ui ->doubleSpinBox_4, SIGNAL (editingFinished()),this, SLOT (mySlot()));@
    @ connect (ui ->doubleSpinBox_5, SIGNAL (editingFinished()),this, SLOT (mySlot()));@
    @ connect (ui ->doubleSpinBox_6, SIGNAL (editingFinished()),this, SLOT (mySlot()));@
    @ connect (ui ->doubleSpinBox_7, SIGNAL (editingFinished()),this, SLOT (mySlot()));@
    @ connect (ui ->doubleSpinBox_8, SIGNAL (editingFinished()),this, SLOT (mySlot()));@
    @ connect (ui ->doubleSpinBox_9, SIGNAL (editingFinished()),this, SLOT (mySlot()));@
    @ connect (ui ->doubleSpinBox_10, SIGNAL (editingFinished()),this, SLOT (mySlot()));@

    This is really tedious work. Can I not "group" or "family" all the input widgets into one group and make it so that if any of them are editingFinished, the output widget will change?



  • I think there isn't such a feature in Qt Creator or even in the Qt library.

    Maybe you could use "QObject::children":http://doc-snapshot.qt-project.org/qdoc/qobject.html#children and "QObject::objectName":http://doc-snapshot.qt-project.org/qdoc/qobject.html#objectName-prop to filter your widgets. For example:
    @
    for(QObject child : widget->children()) {
    if(child->objectName() == /
    some regexp here: doubleSpinBox_N */) {
    connect(child, SIGNAL(editingFinished()), this, SLOT(mySlot()));
    }
    }
    @



  • For this situation you can use "QSignalMapper":http://qt-project.org/doc/qt-5/qsignalmapper.html#details


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.