Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved From QDialog to QWidget

    General and Desktop
    3
    4
    101
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      Szabii last edited by Szabii

      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();
      
      JKSH 1 Reply Last reply Reply Quote 0
      • JKSH
        JKSH Moderators @Szabii last edited by

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

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply Reply Quote 5
        • Kent-Dorfman
          Kent-Dorfman last edited by

          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.

          1 Reply Last reply Reply Quote 3
          • S
            Szabii last edited by

            Thanks, problem solved.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post