Possible to move event slots?



  • I have a couple of QTableWidget instances in a QGroubBox and the tables have a data dependency. When an element is selected in one table data associated with the selected element is written to the second box.

    When I added the slot, the slot entry and the method were added to mainwindow. First, main window at least two levels away from the group box, and it seems reasonable that the group box should be responsible for its operation.

    Is it possible to move the slot from the mainwindow to the groupbox. If all of the slots are managed by mainwindow, the mainwindow will become a very large entity, and very confusing. I know form mainwindow I can send a message to the groupbox to get the work done, it just seems better if I can move it.


  • Lifetime Qt Champion

    Hi,

    Sure you can, just create a custom widget that will have these slots and contain all the needed "sub widgets" , nothing wrong with that at all. You can see it done in Qt's examples and demos



  • I just tried to move the slot and the method from mainwindow to the subclasses QGroupBox that has slots and make complained that it needed the method in mainwindow. I will try it again. Thank you.



  • I just copied the slot and the method, it ran fine but I got a runtime message:

    QMetaObject::connectSlotByName: No matching signal for on_scheduleTable_clicked(QModelIndex)

    Is it because the QGroupBox doesn't have an instance variable for its children?


  • Lifetime Qt Champion

    Did you made a separate widget with designer for each group box ?



  • I made a separate subclass of QGroupBox for each group box I use. I promotted each groupbox in Qt Creator to the respective subclass. I think I need to use connect to make it work, which seems to have been done automatically for me in the mainwindow scenario.

    Sorry, but I have only been able to use Qt for a few days and I am still in the learning phase. I probably should wait longer before I post, but I'm just not sure of the language to know what to search for.


  • Lifetime Qt Champion

    Then just take the documentation and search for Designer, you'll have several guides that will help you


Log in to reply
 

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