Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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");
                    if(strDriveName.at(0)==mdiChild->getBurnDrive().at(0)){
                        qDebug("same window");
                        mdiChild->activateWindow();
                        return;
                    }
                }else{
                    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

    Hi
    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
    https://bugreports.qt.io/browse/QTBUG-44630
    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
    mdiChild->activateWindow();
    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

    @pixbyte
    Hi
    It could be.
    You can report it here
    https://bugreports.qt.io/

    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
    window->activateWindow();
    do the same ?


Log in to reply