Wait until QWidget closes

Wait until QWidget closes

Asked on January 11, 2019 in Qt.
Add Comment


  • 2 Answer(s)

    The QWidget will  be  close:

    In MyClass inherit QDialog.  modal will be open with  dialog  exec()

    void MainWindow::createMyDialog()
    {
      MyClass dialog(this);
      dialog.exec();
    }
    

    Just click this link   http://qt-project.org/doc/qt-4.8/qdialog.html

     

    Answered on January 11, 2019.
    Add Comment

    The alternative code is:

    #include <QEventLoop>
     
    void doStuff()
    {
        // Creating an instance of myClass
        MyClass myInstance;
        // (optional) myInstance.setAttribute(Qt::WA_DeleteOnClose);
        myInstance.show();
     
        // This loop will wait for the window is destroyed
        QEventLoop loop;
        connect(this, SIGNAL(destroyed()), & loop, SLOT(quit()));
        loop.exec();
    }
    
    Answered on January 11, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.