Qt Forum

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

    Solved signal QMdiArea::subWindowActivated(QMdiSubWindow *window) emitted two times while switching

    General and Desktop
    3
    5
    324
    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.
    • A
      Akhendra last edited by

      Hello,

      I have QMdi area with several sub windows added to it.I see the signal subWindowActivated is emitted two times when switching between one sub window to another sub window.
      I see the address of the sub windows and the order is below:
      First it emitted a signal for currently active then
      It emitted a signal for the sub window which is about to activate.
      How to stop the signal which should not emit a signal for currently active and only activate for about to activate.

      Regards,
      Akhendra

      Pl45m4 1 Reply Last reply Reply Quote 0
      • Pl45m4
        Pl45m4 @Akhendra last edited by

        @Akhendra

        I think you'll need to provide a code example of what exactly you did, because it looks like nobody else has problems with the QMdiArea::subWindowActivated signal.

        How do switch your MDI windows? Any chance that the current one gets active before getting replaced or before you switch to new / next MDI window?

        Do you use setActiveSubWindow(QMdiSubWindow *window)? Does this emit your signal twice as well?


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        A 1 Reply Last reply Reply Quote 0
        • A
          Akhendra @Pl45m4 last edited by

          @Pl45m4
          Thank you for your reply.
          Do you use setActiveSubWindow(QMdiSubWindow *window)? Does this emit your signal twice as well?==> I did not use this method to set active window.
          How do switch your MDI windows? ==> I am switching using mouse press event.
          Any chance that the current one gets active before getting replaced or before you switch to new / next MDI window?==> There is no chance the current one get active as it was already active and i am going to switch to activate another window.

          sample code:
          // class for subwindow
          class imagesubwindow : public QMdiSubWindow
          {
          Q_OBJECT

          public:
          explicit imagesubwindow(QWidget *parent = 0)
          {
          setAttribute(Qt::WA_DeleteOnClose);
          setWidget(m_imageViewerWidget);
          }

          };
          int main(int argc, char *argv[])
          {
          QApplication app(argc, argv);

                  MainWindow window;
                  QMdiArea *mdiArea = new QMdiArea();
                  window.setCentralWidget(mdiArea );
          
                  imagesubwindow *subWindow1 = new imagesubwindow();
                 mdiArea ->addSubWindow(subWindow1 );
          
                imagesubwindow *subWindow12 = new imagesubwindow();
                mdiArea ->addSubWindow(subWindow1 )
          
                return app.exec();
          

          }

          1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion last edited by mrjj

            Hi
            Switching between subwindows only fires one signal for me.
            However, on startup, it does get 2 but not while running.
            ( the 2 at start up is as expected as first no 1 is active then, 2 comes and made active )

            But after that -Only on pr switch.

            alt text

            using this test code.

            int main(int argc, char *argv[])
            {
                QApplication app(argc, argv);
            
                MainWindow window;
                QMdiArea *mdiArea = new QMdiArea();
                window.setCentralWidget(mdiArea );
            
                imagesubwindow *subWindow1 = new imagesubwindow();
                mdiArea ->addSubWindow(subWindow1 );
            
                QObject::connect(mdiArea, &QMdiArea::subWindowActivated, []() {
                    static int cc=1;
                    qDebug() << "subWindowActivated = " << cc++;
                });
            
                imagesubwindow *subWindow12 = new imagesubwindow();
                mdiArea ->addSubWindow(subWindow12 );
            
                window.show();
            
                return app.exec();
            }
            
            1 Reply Last reply Reply Quote 3
            • A
              Akhendra last edited by

              Hello mrjj ,

              Thank you for your reply.

              As you mentioned, at startup it emits tow times.
              So in my application my subwindows lost focus( cases like minimize and miaximize the app) due to this the signal get emitted two times.
              Thank you for your quick reply and help.
              Thank you for all.

              Thank you.
              Akhendra

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