⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

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();

    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();

  • Moderators


    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