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
Forum Update on Monday, May 27th 2025

QMessageBox non blocking

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 7 Posters 4.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.
  • SPlattenS SPlatten

    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 last edited by
    #2

    @SPlatten you can try this way...

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

    1 Reply Last reply
    0
    • SPlattenS SPlatten

      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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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.

      artwawA SPlattenS 2 Replies Last reply
      1
      • JonBJ JonB

        @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.

        artwawA Offline
        artwawA Offline
        artwaw
        wrote on 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

        SPlattenS 1 Reply Last reply
        0
        • JonBJ JonB

          @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.

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on 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

          artwawA eyllanescE 2 Replies Last reply
          0
          • artwawA artwaw

            @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...

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on 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
            • SPlattenS SPlatten

              @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.

              artwawA Offline
              artwawA Offline
              artwaw
              wrote on 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 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
                • SPlattenS SPlatten

                  @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.

                  eyllanescE Offline
                  eyllanescE Offline
                  eyllanesc
                  wrote on 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.

                  SPlattenS 1 Reply Last reply
                  0
                  • eyllanescE eyllanesc

                    @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.

                    SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by SPlatten
                    #10

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

                    Kind Regards,
                    Sy

                    eyllanescE 1 Reply Last reply
                    0
                    • SPlattenS SPlatten

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

                      eyllanescE Offline
                      eyllanescE Offline
                      eyllanesc
                      wrote on 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 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