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 exec no longer modal after show
Forum Updated to NodeBB v4.3 + New Features

QDialog exec no longer modal after show

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 678 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.
  • S SGaist
    8 Sept 2023, 17:37

    Hi,

    Are you explicitly setting the modality of your dialog ?

    C Offline
    C Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on 8 Sept 2023, 17:45 last edited by
    #3

    Show() creates a modeless dialog. So don't use it when you want a modal one.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    S 1 Reply Last reply 8 Sept 2023, 17:57
    1
    • S SGaist
      8 Sept 2023, 17:37

      Hi,

      Are you explicitly setting the modality of your dialog ?

      S Offline
      S Offline
      SamiV123
      wrote on 8 Sept 2023, 17:57 last edited by
      #4

      @SGaist

      @SGaist said in QDialog exec no longer modal after show:

      Hi,

      Are you explicitly setting the modality of your dialog ?

      No. setModal(true) doesn't fix the problem though.

      1 Reply Last reply
      0
      • C Christian Ehrlicher
        8 Sept 2023, 17:45

        Show() creates a modeless dialog. So don't use it when you want a modal one.

        S Offline
        S Offline
        SamiV123
        wrote on 8 Sept 2023, 17:57 last edited by
        #5

        @Christian-Ehrlicher said in QDialog exec no longer modal after show:

        Show() creates a modeless dialog. So don't use it when you want a modal one.

        Uh uh, did you read why it's needed?

        C 1 Reply Last reply 8 Sept 2023, 18:17
        0
        • S SamiV123
          8 Sept 2023, 17:57

          @Christian-Ehrlicher said in QDialog exec no longer modal after show:

          Show() creates a modeless dialog. So don't use it when you want a modal one.

          Uh uh, did you read why it's needed?

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 8 Sept 2023, 18:17 last edited by
          #6

          @SamiV123 Yes. Maybe you can convince the devs to change this behavior but I doubt it.
          http://bugreports.qt.io

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 8 Sept 2023, 18:21 last edited by
            #7

            Did you experiment with open as well ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            S 1 Reply Last reply 8 Sept 2023, 19:16
            0
            • S SGaist
              8 Sept 2023, 18:21

              Did you experiment with open as well ?

              S Offline
              S Offline
              SamiV123
              wrote on 8 Sept 2023, 19:16 last edited by
              #8

              @SGaist said in QDialog exec no longer modal after show:

              Did you experiment with open as well ?

              I did, but I don't know what's going on with open(). the whole dialog just disappeared and was not visible. Weird.

              S M 2 Replies Last reply 8 Sept 2023, 19:18
              0
              • S SamiV123
                8 Sept 2023, 19:16

                @SGaist said in QDialog exec no longer modal after show:

                Did you experiment with open as well ?

                I did, but I don't know what's going on with open(). the whole dialog just disappeared and was not visible. Weird.

                S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 8 Sept 2023, 19:18 last edited by
                #9

                Check your dialog lifetime. If it's a function local object then it will be destroyed after calling open since it's the last method call in the function.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                S 1 Reply Last reply 9 Sept 2023, 09:01
                1
                • S SamiV123
                  8 Sept 2023, 19:16

                  @SGaist said in QDialog exec no longer modal after show:

                  Did you experiment with open as well ?

                  I did, but I don't know what's going on with open(). the whole dialog just disappeared and was not visible. Weird.

                  M Offline
                  M Offline
                  mpergand
                  wrote on 8 Sept 2023, 20:49 last edited by
                  #10

                  @SamiV123
                  try this:

                  class DlgMsg : public QDialog
                  {
                  	public:
                  
                  		DlgMsg() : QDialog(nullptr) {}
                  
                  	void showMessage(const QString& str)
                  	{
                  		QTimer::singleShot(1000,this,[str,this]()
                  		{
                  		auto msg=QMessageBox(this);
                  		msg.setWindowModality(Qt::WindowModal);
                  		msg.setText(str);
                  		msg.exec();
                  		});
                  	}
                  };
                  ...
                  DlgMsg dmsg;
                  dmsg.resize(400,200);
                  dmsg.showMessage("Something wrong happened!");
                  
                  dmsg.exec();
                  
                  

                  1 Reply Last reply
                  0
                  • S SGaist
                    8 Sept 2023, 19:18

                    Check your dialog lifetime. If it's a function local object then it will be destroyed after calling open since it's the last method call in the function.

                    S Offline
                    S Offline
                    SamiV123
                    wrote on 9 Sept 2023, 09:01 last edited by
                    #11

                    @SGaist said in QDialog exec no longer modal after show:

                    Check your dialog lifetime. If it's a function local object then it will be destroyed after calling open since it's the last method call in the function.

                    Doh, you're right, so open() returns immediately so of course that will that not work.

                    Actually open() seems very cumbersome to use, it's a lot easier to simply create the Dialog on the stack and call exec()

                    S 1 Reply Last reply 9 Sept 2023, 10:17
                    0
                    • S SamiV123
                      9 Sept 2023, 09:01

                      @SGaist said in QDialog exec no longer modal after show:

                      Check your dialog lifetime. If it's a function local object then it will be destroyed after calling open since it's the last method call in the function.

                      Doh, you're right, so open() returns immediately so of course that will that not work.

                      Actually open() seems very cumbersome to use, it's a lot easier to simply create the Dialog on the stack and call exec()

                      S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 9 Sept 2023, 10:17 last edited by
                      #12

                      As explained in the method documentation, exec has some caveats to take into account when you design your application.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1

                      12/12

                      9 Sept 2023, 10:17

                      • Login

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