Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    [Solved] Signal/Slot connection that spans 3 classes

    General and Desktop
    4
    4
    2086
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      Endless last edited by

      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:
      @
      RootWindow::RootWindow(QWidget *parent) :
      QMainWindow(parent)
      {
      showFullScreen();
      myStackedWidget = new QStackedWidget(this);
      monitorScreen = new MonitorWindow();
      myStackedWidget->addWidget(monitorScreen);
      connect(monitorScreen, SIGNAL(activateScreen(int)), this, SLOT(setCurrentScreen(int)));
      }
      @
      In the monitorwindow.cpp file:
      @
      MonitorWindow::MonitorWindow(QWidget *parent) :
      QWidget(parent),
      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?

      1 Reply Last reply Reply Quote 0
      • D
        d2uriel last edited by

        Maybe something like:
        @connect(this->statusBar, SIGNAL(something()), /maybe a cast here/this->parent(), SLOT(somethingElse()));@
        ?

        No idea if it will work :P.

        "Do not judge, and you will never be mistaken." - Jean-Jacques Rousseau

        1 Reply Last reply Reply Quote 0
        • M
          mlong last edited by

          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.

          @
          RootWindow::RootWindow(QWidget *parent) :
          QMainWindow(parent)
          {
          ...
          monitorScreen = new MonitorWindow();

          connect(monitorScreen, SIGNAL(showSiteMap()), this, SLOT(doWhatever()));
          

          ...
          }
          @

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply Reply Quote 0
          • A
            andre last edited by

            Note that the SIGNAL/SIGNAL connection in the example of mlong above is not a mistake. You can connect signals together.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post