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. [SOLVED] modal QDialog::setVisibible(false) calls the Destructor
Qt 6.11 is out! See what's new in the release blog

[SOLVED] modal QDialog::setVisibible(false) calls the Destructor

Scheduled Pinned Locked Moved General and Desktop
qdialog
7 Posts 3 Posters 4.6k Views 2 Watching
  • 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.
  • Andy314A Offline
    Andy314A Offline
    Andy314
    wrote on last edited by Andy314
    #1

    Hello !

    If I hide a modal dialog, this calls its destructor. This not what I want.
    Must I configure something to avoid it?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      Are you sure its not a case of running out of scope ?

      void func() {
      MyDia A;

      } << A dies here, even if hidden.

      Andy314A 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        Are you sure its not a case of running out of scope ?

        void func() {
        MyDia A;

        } << A dies here, even if hidden.

        Andy314A Offline
        Andy314A Offline
        Andy314
        wrote on last edited by
        #3

        Hello @mrjj !
        Indeed the Destructior comes from by subclassing of the QDialog and some mechansim.
        I have tested it with a simple QDialog now. The main problem stays:

        QDialog d;
        d.exec()               //  in the dialog call hide() under some conditions;
        // resume code
        

        The exec() returns if I hide(). This I dont want. The hide() should be only a visual effect.

        (My program logic seem a little bit strange, but I develop on a tablet a full-screen app with a large dialog-stack. The lower dialogs I want to hide, so that the user seen only the top-dialog in the windows taskbar.)

        mrjjM 1 Reply Last reply
        0
        • Andy314A Andy314

          Hello @mrjj !
          Indeed the Destructior comes from by subclassing of the QDialog and some mechansim.
          I have tested it with a simple QDialog now. The main problem stays:

          QDialog d;
          d.exec()               //  in the dialog call hide() under some conditions;
          // resume code
          

          The exec() returns if I hide(). This I dont want. The hide() should be only a visual effect.

          (My program logic seem a little bit strange, but I develop on a tablet a full-screen app with a large dialog-stack. The lower dialogs I want to hide, so that the user seen only the top-dialog in the windows taskbar.)

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

          @Andy314

          Hi
          Have you tried to give the lower dialog the main window as parent ?
          Like in
          QDialog d(mainwin);
          As that normally will make sure only mainwin has entry in taskbar.

          Hmm not sure you can ask Exec to keep running if you hide the dialog.
          Did you try with Show instead ?
          So you want your dialog to stay alive, but not visible before you press button or how does it become visible again?

          Andy314A 1 Reply Last reply
          0
          • mrjjM mrjj

            @Andy314

            Hi
            Have you tried to give the lower dialog the main window as parent ?
            Like in
            QDialog d(mainwin);
            As that normally will make sure only mainwin has entry in taskbar.

            Hmm not sure you can ask Exec to keep running if you hide the dialog.
            Did you try with Show instead ?
            So you want your dialog to stay alive, but not visible before you press button or how does it become visible again?

            Andy314A Offline
            Andy314A Offline
            Andy314
            wrote on last edited by
            #5

            @mrjj
            Thank you for the tip. With correct parent all work right.
            (My idea before was Hide it -> Exec other Dialog -> after return Show it again.)
            But this is all not needed now.

            Nevertheless only hiding a dialog would be usefull sometimes. Seem that Qt doesnt support it.
            Only Show instead of exec would complicate the program flow and I think the showed dialog wouldnt be enabled if I call it from a modal dialog.

            mrjjM 1 Reply Last reply
            0
            • Andy314A Andy314

              @mrjj
              Thank you for the tip. With correct parent all work right.
              (My idea before was Hide it -> Exec other Dialog -> after return Show it again.)
              But this is all not needed now.

              Nevertheless only hiding a dialog would be usefull sometimes. Seem that Qt doesnt support it.
              Only Show instead of exec would complicate the program flow and I think the showed dialog wouldnt be enabled if I call it from a modal dialog.

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

              @Andy314
              Super.

              Yes, using Show does make program flow more complicated but it can be managed ok easy using signals when when you hide / show dialogs. But I agree with Modal Dialogs, its get messy fast :)

              1 Reply Last reply
              0
              • A Offline
                A Offline
                alex_malyu
                wrote on last edited by alex_malyu
                #7

                @Seem that Qt doesnt support it.

                Modal dialogs have their own event loop which starts when you call exec.
                When dialog is closed by user exec has to return otherwise you stuck - user can't exit exec, cause dialog is hidden.

                But all it does - stops event loop and hides dialog, nothing else.
                This does not delete dialog, so it actually does what you want.
                And you can exec() again.

                MyDialog dialog;

                while ( dialog.exec() == QDialog::Accepted )
                ;

                In your case object is deleted cause it goes out of scope, If you do not want it to be deleted allocate it on the stack.
                But normally you do not want to keep an instance of the modal dialog unless its initialization is really slow.

                Choice between modelless and modal dialog is not made based on the fact you want to keep it hidden.
                Difference is in the ability to interact with other windows/dialogs when your dialog is shown.
                And choice of modality defines which functions you use exec() or show()/hide().

                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