Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDialog window disappears

QDialog window disappears

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 3.8k Views
  • 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 Offline
    S Offline
    Sleicreider
    wrote on last edited by
    #1

    Hi,

    In my main window GUI I'm using the following code to show a popup window without creating a icon on the taskbar:

    @
    GUI...{
    QDialog popup;
    QMainWindow mainWindow(&popup);
    mainWindow.show();
    }
    @

    somehow it appears for half a second and then disappear.

    anyone can help?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Sure. You're making a common mistake. As soon as the variables you declared (both popup and mainWindow) go out of scope, that is, your function reaches the closing } on line 5, their destructor gets called.

      You'll need to allocate objects that need to live beyond the lifetime of your function on the heap instead. Use the keyword "new" for that.

      S 1 Reply Last reply
      0
      • S Offline
        S Offline
        Sleicreider
        wrote on last edited by
        #3

        uff,
        of course you're right.

        i feel embarrassed now :P

        1 Reply Last reply
        0
        • A andre

          Sure. You're making a common mistake. As soon as the variables you declared (both popup and mainWindow) go out of scope, that is, your function reaches the closing } on line 5, their destructor gets called.

          You'll need to allocate objects that need to live beyond the lifetime of your function on the heap instead. Use the keyword "new" for that.

          S Offline
          S Offline
          shukyp
          wrote on last edited by shukyp
          #4

          @andre

          Your answer makes sense if the below API is a non-blocking one
          mainWindow.show();

          I'm absolutely new (my first days) with Qt.
          My expectation is that show() would be a blocking API, so the dialog would stay until its activity is done
          using a signal->(exit)slot. Obviously, it isn't the case.

          My intention is to call a Modal dialog. So I want both dialogs/forms to stay.

          Their design approach is embarrassing (at least surprising). Why enforce dynamic allocation? this is up to the software designer, for sure not to a library designer to decide.

          I'm using Qt 6.x, is there any blocking API of the kind I'm looking for? or any other solution except memory allocation?

          In light of this given behavior, then how the flow will return to the invoking dialog once the called dialog terminates?
          is this managed somehow by QtCore?

          Appreciate if someone can enrich my knowledge on the above.

          Many Thanks

          JonBJ mrjjM 2 Replies Last reply
          0
          • S shukyp

            @andre

            Your answer makes sense if the below API is a non-blocking one
            mainWindow.show();

            I'm absolutely new (my first days) with Qt.
            My expectation is that show() would be a blocking API, so the dialog would stay until its activity is done
            using a signal->(exit)slot. Obviously, it isn't the case.

            My intention is to call a Modal dialog. So I want both dialogs/forms to stay.

            Their design approach is embarrassing (at least surprising). Why enforce dynamic allocation? this is up to the software designer, for sure not to a library designer to decide.

            I'm using Qt 6.x, is there any blocking API of the kind I'm looking for? or any other solution except memory allocation?

            In light of this given behavior, then how the flow will return to the invoking dialog once the called dialog terminates?
            is this managed somehow by QtCore?

            Appreciate if someone can enrich my knowledge on the above.

            Many Thanks

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @shukyp
            If I had been you I would have created a new thread for this, not posted in one from 2014! :)

            If you are asking how to show a modal dialog and "block", while the user interacts with that dialog. then you want QDialog::exec(). QDialog::show() is non-blocking, like QMainWindow::show().

            1 Reply Last reply
            2
            • S shukyp

              @andre

              Your answer makes sense if the below API is a non-blocking one
              mainWindow.show();

              I'm absolutely new (my first days) with Qt.
              My expectation is that show() would be a blocking API, so the dialog would stay until its activity is done
              using a signal->(exit)slot. Obviously, it isn't the case.

              My intention is to call a Modal dialog. So I want both dialogs/forms to stay.

              Their design approach is embarrassing (at least surprising). Why enforce dynamic allocation? this is up to the software designer, for sure not to a library designer to decide.

              I'm using Qt 6.x, is there any blocking API of the kind I'm looking for? or any other solution except memory allocation?

              In light of this given behavior, then how the flow will return to the invoking dialog once the called dialog terminates?
              is this managed somehow by QtCore?

              Appreciate if someone can enrich my knowledge on the above.

              Many Thanks

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              Hi welcome to the forums.

              • Their design approach is embarrassing (at least surprising). Why enforce dynamic allocation? this is up to the software designer, for sure not to a library designer to decide.

              They dont.

              you can easy do like
              {
              MyDialog dia;
              dia.exec(); // blockes
              } // deleted here

              However for Widgets in a parent - child relation ship, you should use dynamic allocation
              to be able to use the auto cleaning system/owner system
              https://doc.qt.io/qt-5/objecttrees.html
              Or at least be very careful not to get double deletes.

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved