Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. signal QMdiArea::subWindowActivated(QMdiSubWindow *window) emitted two times while switching
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 957 Views 2 Watching
  • 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 Offline
    A Offline
    Akhendra
    wrote on last edited by
    #1

    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

    Pl45m4P 1 Reply Last reply
    0
    • A Akhendra

      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

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @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
      0
      • Pl45m4P Pl45m4

        @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?

        A Offline
        A Offline
        Akhendra
        wrote on last edited by
        #3

        @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
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          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
          3
          • A Offline
            A Offline
            Akhendra
            wrote on last edited by
            #5

            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
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved