Search code examples
qtwidgetsignals-slotsqdockwidget

signals/slots setup in Dock widget that contains many tab widgets


I have a class that inherits QDockWidget. This class has four QTabWidgets in it (tcp stuff, ftp stuff, sql stuff and settings), each of which has its own functionality meaning each one has different signals/slots that need to be captured or called. Each tab has a few signals/slots that are important for the main UI to capture or call.Is there a way to prevent having to litter my QDockWidget class with signals and slots from the tab widgets it contains or is this just how it needs to be done?


Solution

  • You can define getter functions in the header file of your QDockWidget subclass like:

    inline QWidget* tcpStuffWidget() { return <pointer_to_widget>; }
    

    and in the main UI you can then do something like

    connect( dockWidget()->tcpStuffWidget(), SIGNAL( ... ),
             this                          , SLOT  ( ... ) );