[ACCEPTED]-Wait until QWidget closes-qt

Accepted answer
Score: 31

Have MyClass inherit QDialog. Then open it as a modal 1 dialog with exec().

void MainWindow::createMyDialog()
  MyClass dialog(this);

Check out http://qt-project.org/doc/qt-4.8/qdialog.html

Score: 15

An other way is to use a loop which waits 1 on the closing event :

#include <QEventLoop>

void doStuff()
    // Creating an instance of myClass
    MyClass myInstance;
    // (optional) myInstance.setAttribute(Qt::WA_DeleteOnClose);  

    // This loop will wait for the window is destroyed
    QEventLoop loop;
    connect(this, SIGNAL(destroyed()), & loop, SLOT(quit()));
Score: 0

Why not put the code you don't want to be 3 executed till the window has closed in a 2 separate function and connect this as a 1 SLOT for the window's close SIGNAL?

More Related questions