Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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



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



  • @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();
    

    }


  • Lifetime Qt Champion

    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();
    }
    


  • 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


Log in to reply