Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

From QDialog to QWidget



  • Hi!

    I have a Main Menu based on QDialog. I can open several QDialogs from here but now, I need to create a QWidget, which can't be open the sam way as QDialogs. As we know, we can open a new QDialog with the following code:

    qdialogName variableName();
    variableName.setModal(true);
    variableName.exec();
    

    But now, as I said before, I have to open a QWidget window from my QDialog menu. I didn't find any solution for that, so I'd appreciate it if someone could help me with this. I tried the following code but didn't work (from my QDialog menu onButtonClick):

    qwidgetName variableName();
    variableName.setMOdal(true);
    variableName.exec();
    

  • Moderators

    @Szabii

    1. If your widget is a local variable in your function, it will be destroyed when the function returns.
    2. See the documentation for QWidget::show()


  • You need to understand that QDialog is a specialization of QWidget that has its own event loop. setModal isn't defined in QWidget as widgets simply post events to the main GUI event loop. QDialog is a bit different in that it has the appearance of running its own event loop, even if the implementation doesn't specifically do that. IOW, you don't exec() a regular widget.



  • Thanks, problem solved.


Log in to reply