Important: Please read the 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)


  • 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

    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.

    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