[Solved] Signal/Slot connection that spans 3 classes
I have the RootWindow class which is a QMainWindow. I then instantiate the MonitorWindow class, a QWidget, from RootWindow. Next, in the constructor of MonitorWindow, I instantiate another class called StatusBar, which shows a status bar on the MonitorWindow QWidget. Here are the code snippets that do the above:
In the rootwindow.cpp file:
- {
- showFullScreen();
- monitorScreen = new MonitorWindow();
- myStackedWidget->addWidget(monitorScreen);
- connect(monitorScreen, SIGNAL(activateScreen(int)), this, SLOT(setCurrentScreen(int)));
- }
In the monitorwindow.cpp file:
- ui(new Ui::MonitorWindow)
- {
- ui->setupUi(this);
- // Instantiate status bar and connect it
- statusBar = new StatusBar(this);
- connect(this, SIGNAL(statusChanged(int)), statusBar, SLOT(updateStatusSlot(int)));
- connect(this, SIGNAL(faultStatusChanged(int)), statusBar, SLOT(updateFaultSlot(int)));
- connect(statusBar, SIGNAL(showSiteMap()), this, SLOT(sendSiteMapRequest()));
- }
What I’d like to do is add a fourth connection to the three listed immediately above that connects a signal from StatusBar to a slot in RootWindow. Since RootWindow is two levels above StatusBar, how would I go about doing that?
3 replies
Create a duplicate signal in your MonitorWindow class and chain them together. For instance, if you wanted to expose the statusbar’s showSiteMap signal, you could do:
- class MonitorWindow ...
- {
- ...
- signal:
- void showSiteMap();
- ...
- }
And in the c’tor do:
- MonitorWindow::MonitorWindow(...)
- {
- ...
- statusBar = new StatusBar(...);
- connect(statusBar, SIGNAL(showSiteMap()), this, SIGNAL(showSiteMap()));
- ...
- }
Then in your root window you can connect to MonitorWindow’s “showSiteMap()” signal.
- {
- ...
- monitorScreen = new MonitorWindow();
- connect(monitorScreen, SIGNAL(showSiteMap()), this, SLOT(doWhatever()));
- ...
- }
You must log in to post a reply. Not a member yet? Register here!


