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. How to create qmessage box with shoew
Forum Update on Monday, May 27th 2025

How to create qmessage box with shoew

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 748 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.
  • T Offline
    T Offline
    TheCeylann
    wrote on last edited by
    #1

    Hello, I'm new to the qt world. I have a problem with show() and exec().

    I am reading a series of data over the serial port and I want to show a message on the screen like please wait until the data comes from my port. When my serial port is empty, I hide that text.

    When I use it this way, the messagebox doesn't continue with other processes until it closes

    QMessageBox msgBox;
        msgBox.setWindowFlags(Qt::WindowType::Popup);
        msgBox.setText("Please Wait");
        msgBox.exec();
    

    .If I type show() instead of exec() , the messagebox appears as I want and continues with other operations. but the please wait text that I defined does not appear.

    QMessageBox msgBox;
        msgBox.setWindowFlags(Qt::WindowType::Popup);
        msgBox.setText("Please Wait");
        msgBox.show();
    

    If my serial port is empty, I hide the messagebox.

    here is my all code.

    void MainWindow::on_pushButton_4_clicked()
    {
        QMessageBox msgBox;
        msgBox.setWindowFlags(Qt::WindowType::Popup);
        msgBox.setText("Please Wait");
        msgBox.show();
    //Here I'm getting datas with QSerialPort after create message.
     if(serialInput.isEmpty()){
           msgBox.hide();
             QMessageBox::information(this, "Info", "Proggress Completed..");
           
         }
    

    What can I do to show the Please wait message and continue at the same time?

    M JonBJ 2 Replies Last reply
    0
    • T TheCeylann

      Hello, I'm new to the qt world. I have a problem with show() and exec().

      I am reading a series of data over the serial port and I want to show a message on the screen like please wait until the data comes from my port. When my serial port is empty, I hide that text.

      When I use it this way, the messagebox doesn't continue with other processes until it closes

      QMessageBox msgBox;
          msgBox.setWindowFlags(Qt::WindowType::Popup);
          msgBox.setText("Please Wait");
          msgBox.exec();
      

      .If I type show() instead of exec() , the messagebox appears as I want and continues with other operations. but the please wait text that I defined does not appear.

      QMessageBox msgBox;
          msgBox.setWindowFlags(Qt::WindowType::Popup);
          msgBox.setText("Please Wait");
          msgBox.show();
      

      If my serial port is empty, I hide the messagebox.

      here is my all code.

      void MainWindow::on_pushButton_4_clicked()
      {
          QMessageBox msgBox;
          msgBox.setWindowFlags(Qt::WindowType::Popup);
          msgBox.setText("Please Wait");
          msgBox.show();
      //Here I'm getting datas with QSerialPort after create message.
       if(serialInput.isEmpty()){
             msgBox.hide();
               QMessageBox::information(this, "Info", "Proggress Completed..");
             
           }
      

      What can I do to show the Please wait message and continue at the same time?

      M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      @TheCeylann
      Hi,

      You have to create a instance variable in MainWindow.
      In the MainWindow.h

      QMessageBox* mskBox=nullptr;
      

      and in .cpp

      if(msgBox==nullptr)
        {
        msgBox=new QMessageBox(this);
        }
        msgBox->setText("Please Wait");
        msgBox->show();
      

      Or create the msgBox instance in the construtor.

      Here I'm getting datas with QSerialPort after create message.

      For that, use signals & slots.

      T 1 Reply Last reply
      1
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        @TheCeylann said in How to create qmessage box with shoew:

        What can I do to show the Please wait message and continue at the same time?

        The reason this is not occurring now is the lifetime of the QMessageBox instance you create on the stack is the duration of the MainWindow::on_pushButton_4_clicked() call. When the slot exits, the QMessageBox you want to show() is destroyed.

        @mpergand provides a way to ensure the lifetime of the object extends beyond the MainWindow::on_pushButton_4_clicked() call.

        1 Reply Last reply
        0
        • T TheCeylann

          Hello, I'm new to the qt world. I have a problem with show() and exec().

          I am reading a series of data over the serial port and I want to show a message on the screen like please wait until the data comes from my port. When my serial port is empty, I hide that text.

          When I use it this way, the messagebox doesn't continue with other processes until it closes

          QMessageBox msgBox;
              msgBox.setWindowFlags(Qt::WindowType::Popup);
              msgBox.setText("Please Wait");
              msgBox.exec();
          

          .If I type show() instead of exec() , the messagebox appears as I want and continues with other operations. but the please wait text that I defined does not appear.

          QMessageBox msgBox;
              msgBox.setWindowFlags(Qt::WindowType::Popup);
              msgBox.setText("Please Wait");
              msgBox.show();
          

          If my serial port is empty, I hide the messagebox.

          here is my all code.

          void MainWindow::on_pushButton_4_clicked()
          {
              QMessageBox msgBox;
              msgBox.setWindowFlags(Qt::WindowType::Popup);
              msgBox.setText("Please Wait");
              msgBox.show();
          //Here I'm getting datas with QSerialPort after create message.
           if(serialInput.isEmpty()){
                 msgBox.hide();
                   QMessageBox::information(this, "Info", "Proggress Completed..");
                 
               }
          

          What can I do to show the Please wait message and continue at the same time?

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

          @TheCeylann
          In addition to the preceding comments about the message box. After you go show() you have

          //Here I'm getting datas with QSerialPort after create message.

          followed by testing the serialInput and maybe hiding the message box. This is not the way to go in Qt. What does your commented code actually do? If it blocks while waiting for serial input it will also block your UI from user responsiveness because you are inside a slot.

          The Qt way is to display your modeless message box (per what the others have said about scope) and then exit the slot. Then to allow the serial input to arrive in the background and use signals and slots to communicate when data has arrived and close the message box at a future time.

          T JonBJ 2 Replies Last reply
          0
          • M mpergand

            @TheCeylann
            Hi,

            You have to create a instance variable in MainWindow.
            In the MainWindow.h

            QMessageBox* mskBox=nullptr;
            

            and in .cpp

            if(msgBox==nullptr)
              {
              msgBox=new QMessageBox(this);
              }
              msgBox->setText("Please Wait");
              msgBox->show();
            

            Or create the msgBox instance in the construtor.

            Here I'm getting datas with QSerialPort after create message.

            For that, use signals & slots.

            T Offline
            T Offline
            TheCeylann
            wrote on last edited by
            #5

            @mpergand When I try thıs , msgBox->setText("Please Wait"); shown like that.

            When I use show()

            M 1 Reply Last reply
            0
            • JonBJ JonB

              @TheCeylann
              In addition to the preceding comments about the message box. After you go show() you have

              //Here I'm getting datas with QSerialPort after create message.

              followed by testing the serialInput and maybe hiding the message box. This is not the way to go in Qt. What does your commented code actually do? If it blocks while waiting for serial input it will also block your UI from user responsiveness because you are inside a slot.

              The Qt way is to display your modeless message box (per what the others have said about scope) and then exit the slot. Then to allow the serial input to arrive in the background and use signals and slots to communicate when data has arrived and close the message box at a future time.

              T Offline
              T Offline
              TheCeylann
              wrote on last edited by
              #6

              @JonB
              My commented code. If the serial connection is open, it sends a command to my card that allows it to send data and waits for the data to arrive. When my serial port stops sending data. I'm showing all data read receipts. When I send the command and the data starts coming in. I need to show the message Please wait. until my serial port is isEmpty. but when I do it with show, the text I wrote with setText does not appear.

              1 Reply Last reply
              0
              • JonBJ JonB

                @TheCeylann
                In addition to the preceding comments about the message box. After you go show() you have

                //Here I'm getting datas with QSerialPort after create message.

                followed by testing the serialInput and maybe hiding the message box. This is not the way to go in Qt. What does your commented code actually do? If it blocks while waiting for serial input it will also block your UI from user responsiveness because you are inside a slot.

                The Qt way is to display your modeless message box (per what the others have said about scope) and then exit the slot. Then to allow the serial input to arrive in the background and use signals and slots to communicate when data has arrived and close the message box at a future time.

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

                @TheCeylann

                allows it to send data and waits for the data to arrive

                @JonB said in How to create qmessage box with shoew:

                The Qt way is to display your modeless message box (per what the others have said about scope) and then exit the slot. Then to allow the serial input to arrive in the background and use signals and slots to communicate when data has arrived and close the message box at a future time.

                1 Reply Last reply
                0
                • T TheCeylann

                  @mpergand When I try thıs , msgBox->setText("Please Wait"); shown like that.

                  When I use show()

                  M Offline
                  M Offline
                  mpergand
                  wrote on last edited by
                  #8

                  @TheCeylann

                  Use msgBox.open() instead, turns out show() use modal mode !
                  or do: msgBox.setModal(false);

                  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