Important: Please read the Qt Code of Conduct -

Problem after iterate through a midsubwindowlist

  • I hope I get some help into a QT problem I have. I have a App with mdiArea. Everything works fine, but I have one issue:

    If I open first window1 then window2, everything works well. If I click now again on the button to create window2, I iterate through the mdisubwindowlist.

       foreach (QMdiSubWindow *window, mdiArea->subWindowList()) {
            MdiChildBase *mdiChild = qobject_cast<MdiChildBase *>(window->widget());
            if (nullptr != mdiChild){
                qDebug("Ist Childbase");
                RuleManager::ProjectType tProject = mdiChild->GetProjectType();
                if(tProject == RuleManager::TYPE_PROJECT_DISKINFO){
                    qDebug("Ist Diskinfo");
                        qDebug("same window");
                    qDebug("Nicht Diskinfo");

    After the code iterate through the subwindowlist, I get the problem, that on another click the window1 will become active window. But the code will set window2 as active.

    It looks like the iterate an object_cast will do something with the sub windows created.
    Is there an error in my iterate code? Do I have to release the not "needed" sub windows?

  • Lifetime Qt Champion

    The code looks fine. Casting a base QWidget * to your actual subclass should no do anything to the focus handling.

    It does sound like this
    But not completely the same.

    Just to understand.
    You open win1 and win2
    then when you click button 2 again, it checks to see if already open
    and if finds it then try to set focus to it.
    However, on the screen, the MdiWin 1 get focus and not Mdiwin2 as
    one should expect since you set focus in code.

    One thing that i did wonder.
    You take the inner widget (window->widget())
    and call
    on it. However, its technically not the actual window so i wonder if it makes
    any difference doing
    window->activateWindow(); instead ?

  • I think it is a QT bug.

  • Lifetime Qt Champion

    It could be.
    You can report it here

    Please make small complete example that reproduces this behavior to be included
    in the bug report. If you don't - its very unlikely its ever looked at.

    Also, did
    do the same ?

Log in to reply