Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

signal slot from different classes



  • Hi everyone,

    I have two different classes,
    one of them has comboBox, another one has multiple page.
    I would like to change page with respect to selection of comboBox items.
    Have anyone idea, how can i do it?
    Thank you. (I am new to C++ and new to QT)

    Greetings


  • Moderators

    Somewhere in your class hierarchy, these 2 classes certainly have some common parent (like a QMainWindow for example) - that's where you can connect the signals from combo box to your multipage widget.



  • Hi Sierdzio,
    thank you for fast answer. I assume i get it wrong. Should i implement the connect(..) in the parent class? because it will not see comboBox object. As said, i am new, maybe i am missing something.


  • Lifetime Qt Champion

    Hi
    What @sierdzio means is that the best place to hook signal and slot up is where you know
    both classes have have access to the instances.
    Often that is mainwindow.

    So where you create the Selector (combo) and Pages class, there you can
    connect up so the selection in the combo can be hooked up to some slot that can flip the pages.

    Here is small example that has a tab widget on mainwindow and button that opens
    dialog and makes the tabwidget change page from dialog.
    https://www.dropbox.com/s/16rdw8g7zl6ie18/myotherdialog.zip?dl=0

    Note that i use exec() and not show() but works 100% the same.

    Since the combobox is private to the holding class, you just create a new public signal that
    the outside world can connect to. and maybe a new public slot for the pages class.


Log in to reply