There is a main window of type QWidget which calls another window of the same class using the StartFunc() function:

 void Anime::StartFunc() { secondW = new Form; secondW->show(); secondW->activateWindow(); qDebug() << "Target reached"; } 

The task is to call the secondW->activateWindow(); method secondW->activateWindow(); the function stopped, waited for the secondW widget to secondW and only then continued to work (call qDebug() << "Target reached"; ).

My experience suggests that you need to do another method in the secondW object which will spin and not give up until a signal comes to close the window. But it seems to me that this is a crutch method and there is a more correct and adequate solution. Is there such a solution?

    2 answers 2

    You need to inherit your window from QDialog and use the exec method

    • Yes, I thought about that too - Madisson

    What you need is called modality. Modal windows are those windows that make all other windows inactive and do not allow any input into them until this window is closed. In this case, use the setWindowModality method.

     void Anime::StartFunc() { secondW = new Form; secondW->setWindowModality(Qt::ApplicationModal); secondW->show(); secondW->activateWindow(); qDebug() << "Target reached"; } 
    • The window does get to the top of all windows, but this does not stop the function. 'qDebug () << "Target reached";' still running. - Madisson