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. QMessageBox non blocking
QtWS25 Last Chance

QMessageBox non blocking

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 7 Posters 4.7k 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
    SPlatten
    wrote on 29 Sept 2021, 09:45 last edited by
    #1

    I would like to display a simple QMessageBox that is non blocking that is present whilst my application works in the background, I have added an instance of QMessageBox to my class and before the work starts:

    mmsgBox.setText(tr("Scanning file, please wait..."));
    mmsgBox.setWindowModality(Qt::NonModal);
    mmsgBox.exec();
    

    Calling exec causes the message box to be displayed with the text visible but execution is halted until the message box is closed. If I replace exec with show then the message box is displayed and it doesn't halt which is what I want and need but its empty and the text isn't showing.

    What do I need to do to resolve this?

    Kind Regards,
    Sy

    S J 2 Replies Last reply 29 Sept 2021, 09:52
    0
    • S SPlatten
      29 Sept 2021, 09:45

      I would like to display a simple QMessageBox that is non blocking that is present whilst my application works in the background, I have added an instance of QMessageBox to my class and before the work starts:

      mmsgBox.setText(tr("Scanning file, please wait..."));
      mmsgBox.setWindowModality(Qt::NonModal);
      mmsgBox.exec();
      

      Calling exec causes the message box to be displayed with the text visible but execution is halted until the message box is closed. If I replace exec with show then the message box is displayed and it doesn't halt which is what I want and need but its empty and the text isn't showing.

      What do I need to do to resolve this?

      S Offline
      S Offline
      Sai Raul
      wrote on 29 Sept 2021, 09:52 last edited by
      #2

      @SPlatten you can try this way...

      QMessageBox::information (this, "Scanning file, please wait...");

      1 Reply Last reply
      0
      • S SPlatten
        29 Sept 2021, 09:45

        I would like to display a simple QMessageBox that is non blocking that is present whilst my application works in the background, I have added an instance of QMessageBox to my class and before the work starts:

        mmsgBox.setText(tr("Scanning file, please wait..."));
        mmsgBox.setWindowModality(Qt::NonModal);
        mmsgBox.exec();
        

        Calling exec causes the message box to be displayed with the text visible but execution is halted until the message box is closed. If I replace exec with show then the message box is displayed and it doesn't halt which is what I want and need but its empty and the text isn't showing.

        What do I need to do to resolve this?

        J Offline
        J Offline
        JonB
        wrote on 29 Sept 2021, 09:52 last edited by JonB
        #3

        @SPlatten said in QMessageBox non blocking:

        If I replace exec with show then the message box is displayed and it doesn't halt which is what I want and need but its empty and the text isn't showing.

        That is the right thing to do, but I don't know why the text does not show. See https://stackoverflow.com/questions/49266964/how-to-make-qmessagebox-non-modal for solutuon claiming it works. Don't know your platform or if that makes any differnce. With show() have you made sure your mmsgBox's scope persists (should be OK if the leading m implies class member variable)? [Oh, just seen you say it is class-wide.] Or https://stackoverflow.com/questions/3211490/how-to-make-a-non-blocking-non-modal-qmessagebox claims it works with QMessageBox::open() rather than show().

        @Sai-Raul said in QMessageBox non blocking:

        QMessageBox::information (this, "Scanning file, please wait...");

        Docs state:

        The message box is an application modal dialog box.

        OP wants a modeless/non-modal message box.

        A S 2 Replies Last reply 29 Sept 2021, 10:06
        1
        • J JonB
          29 Sept 2021, 09:52

          @SPlatten said in QMessageBox non blocking:

          If I replace exec with show then the message box is displayed and it doesn't halt which is what I want and need but its empty and the text isn't showing.

          That is the right thing to do, but I don't know why the text does not show. See https://stackoverflow.com/questions/49266964/how-to-make-qmessagebox-non-modal for solutuon claiming it works. Don't know your platform or if that makes any differnce. With show() have you made sure your mmsgBox's scope persists (should be OK if the leading m implies class member variable)? [Oh, just seen you say it is class-wide.] Or https://stackoverflow.com/questions/3211490/how-to-make-a-non-blocking-non-modal-qmessagebox claims it works with QMessageBox::open() rather than show().

          @Sai-Raul said in QMessageBox non blocking:

          QMessageBox::information (this, "Scanning file, please wait...");

          Docs state:

          The message box is an application modal dialog box.

          OP wants a modeless/non-modal message box.

          A Offline
          A Offline
          artwaw
          wrote on 29 Sept 2021, 10:06 last edited by
          #4

          @JonB said in QMessageBox non blocking:

          QMessageBox::open()

          With regards to that part: exec() spins up another event loop while open() does not. Can't tell about show(). So I think it's just try and test situation...

          For more information please re-read.

          Kind Regards,
          Artur

          S 1 Reply Last reply 29 Sept 2021, 10:07
          0
          • J JonB
            29 Sept 2021, 09:52

            @SPlatten said in QMessageBox non blocking:

            If I replace exec with show then the message box is displayed and it doesn't halt which is what I want and need but its empty and the text isn't showing.

            That is the right thing to do, but I don't know why the text does not show. See https://stackoverflow.com/questions/49266964/how-to-make-qmessagebox-non-modal for solutuon claiming it works. Don't know your platform or if that makes any differnce. With show() have you made sure your mmsgBox's scope persists (should be OK if the leading m implies class member variable)? [Oh, just seen you say it is class-wide.] Or https://stackoverflow.com/questions/3211490/how-to-make-a-non-blocking-non-modal-qmessagebox claims it works with QMessageBox::open() rather than show().

            @Sai-Raul said in QMessageBox non blocking:

            QMessageBox::information (this, "Scanning file, please wait...");

            Docs state:

            The message box is an application modal dialog box.

            OP wants a modeless/non-modal message box.

            S Offline
            S Offline
            SPlatten
            wrote on 29 Sept 2021, 10:06 last edited by
            #5

            @JonB , just tried this, still the same, calling open instead of show doesn't block but neither does it open the dialog with the text being displayed.

            Kind Regards,
            Sy

            A E 2 Replies Last reply 29 Sept 2021, 10:08
            0
            • A artwaw
              29 Sept 2021, 10:06

              @JonB said in QMessageBox non blocking:

              QMessageBox::open()

              With regards to that part: exec() spins up another event loop while open() does not. Can't tell about show(). So I think it's just try and test situation...

              S Offline
              S Offline
              SPlatten
              wrote on 29 Sept 2021, 10:07 last edited by
              #6

              @artwaw I think its the event loop that is key, obviously thats what causes the text to be displayed.

              Kind Regards,
              Sy

              1 Reply Last reply
              0
              • S SPlatten
                29 Sept 2021, 10:06

                @JonB , just tried this, still the same, calling open instead of show doesn't block but neither does it open the dialog with the text being displayed.

                A Offline
                A Offline
                artwaw
                wrote on 29 Sept 2021, 10:08 last edited by
                #7

                @SPlatten Fastest solution, I think, would be to implement some window based in QDialog, with setter method for the text and such. Annoying, I know, but that will work for sure.

                For more information please re-read.

                Kind Regards,
                Artur

                1 Reply Last reply
                1
                • M Offline
                  M Offline
                  mpergand
                  wrote on 29 Sept 2021, 11:42 last edited by mpergand
                  #8

                  I made some test on Mac.

                  QMessageBox box;
                       box.setText("hello");
                       box.move(30,30);
                       box.open();
                       box.raise();
                  

                  It works but the msgbox appears behind QtCreator and so hidden !
                  What's the reason why i add box.raised()
                  Everything seems ok, i can interact with other windows, and the default OK button closes the msgbox.

                  1 Reply Last reply
                  0
                  • S SPlatten
                    29 Sept 2021, 10:06

                    @JonB , just tried this, still the same, calling open instead of show doesn't block but neither does it open the dialog with the text being displayed.

                    E Offline
                    E Offline
                    eyllanesc
                    wrote on 29 Sept 2021, 11:44 last edited by
                    #9

                    @SPlatten I suspect that the cause is that mmsgBox is a local variable, a basic C++ rule: what happens to a local variable when the function where it is used is finished executing? Well, they are eliminated. The solution could be to extend its scope for example by making a member of the class.

                    If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                    S 1 Reply Last reply 29 Sept 2021, 11:44
                    0
                    • E eyllanesc
                      29 Sept 2021, 11:44

                      @SPlatten I suspect that the cause is that mmsgBox is a local variable, a basic C++ rule: what happens to a local variable when the function where it is used is finished executing? Well, they are eliminated. The solution could be to extend its scope for example by making a member of the class.

                      S Offline
                      S Offline
                      SPlatten
                      wrote on 29 Sept 2021, 11:44 last edited by SPlatten
                      #10

                      @eyllanesc , No it isn't mmsgBox is a class member, 'm' = member.

                      Kind Regards,
                      Sy

                      E 1 Reply Last reply 29 Sept 2021, 11:44
                      0
                      • S SPlatten
                        29 Sept 2021, 11:44

                        @eyllanesc , No it isn't mmsgBox is a class member, 'm' = member.

                        E Offline
                        E Offline
                        eyllanesc
                        wrote on 29 Sept 2021, 11:44 last edited by
                        #11

                        @SPlatten The please provide a minimal and reproducible example.

                        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                        1 Reply Last reply
                        0
                        • I Offline
                          I Offline
                          Ioneater
                          wrote on 6 Aug 2023, 10:18 last edited by
                          #12

                          Try using QApplication::processEvents() after show() and before the work starts. This solved the issue for me.

                          1 Reply Last reply
                          0

                          • Login

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