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 don't show widgets, when method show() calling
Forum Updated to NodeBB v4.3 + New Features

QDialog don't show widgets, when method show() calling

Scheduled Pinned Locked Moved Solved General and Desktop
26 Posts 8 Posters 12.9k Views 3 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.
  • O Offline
    O Offline
    oBOXPOH
    wrote on last edited by oBOXPOH
    #1

    Hello everybody!

    I have some problem. I want to make custom dialog just with message, while operation executing. Code of dialog (.cpp):

    WaitingDialog::WaitingDialog(QWidget *parent) :
        QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
    {
        mainLayout = new QHBoxLayout;
    
        textLabel = new QLabel(tr("Executing..."));
        mainLayout->addWidget(textLabel);
    
        setLayout(mainLayout);
    
        setWindowTitle(tr("Waiting"));
    }
    
    WaitingDialog::~WaitingDialog(){}
    

    Creation of the dialog:

    WaitingDialog dlg(this); //this - some custom widget
    dlg.show();
    
    //some code
    
    dlg.close();
    

    When I call show() method, in this dialog I don't see content of the dialog, except title. When I call exec() method, the dialog display correctly, but this method makes the dialog modal, but I want see this dialog during executing some task.

    Thanks a lot!

    SOLUTION from VRonin

    Add QApplication::processEvents(); after dlg.show();

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by mostefa
      #2

      Hi @oBOXPOH

      I think that the reason is this line:

      dlg.close();

      You QDialog work with exec() method cause close() method does not affect exec(),

      The qt doc says that exec()

      Shows the dialog as a modal dialog, blocking until the user closes it.

      1 Reply Last reply
      1
      • Vinod KuntojiV Offline
        Vinod KuntojiV Offline
        Vinod Kuntoji
        wrote on last edited by
        #3

        @oBOXPOH ,

        Do not set the parent to the dailog,

        WaitingDialog *dailog = new WaitingDailog;
        dailog->show();

        C++, Qt, Qt Quick Developer,
        PthinkS, Bangalore

        O 1 Reply Last reply
        0
        • Vinod KuntojiV Vinod Kuntoji

          @oBOXPOH ,

          Do not set the parent to the dailog,

          WaitingDialog *dailog = new WaitingDailog;
          dailog->show();

          O Offline
          O Offline
          oBOXPOH
          wrote on last edited by
          #4

          @Vinod-Kuntoji said in QDialog don't show widgets, when method show() calling:

          @oBOXPOH ,

          Do not set the parent to the dailog,

          WaitingDialog *dailog = new WaitingDailog;
          dailog->show();

          Thanks for answer!

          This solution didn't help me...

          1 Reply Last reply
          0
          • Pradeep KumarP Offline
            Pradeep KumarP Offline
            Pradeep Kumar
            wrote on last edited by
            #5

            Hi,

            @oBOXPOH ,

            can u use exec(), and based on the condition use close(),

            As u have provided

            WaitingDialog dlg(this); //this - some custom widget
            dlg.show();
            
            //some code
            
            dlg.close();
            

            remove dlg.close() and check whether u will get dialog.

            Thanks,

            Pradeep Kumar
            Qt,QML Developer

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Can you show the complete method code where you create that dialog ?

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

              O 1 Reply Last reply
              0
              • Pradeep KumarP Offline
                Pradeep KumarP Offline
                Pradeep Kumar
                wrote on last edited by
                #7

                hi,

                And u said u need to get the dialog on perform of some task, can u specify the situation ?. when u need and based on that, u can call the dialog in slot.

                Thanks,

                Pradeep Kumar
                Qt,QML Developer

                1 Reply Last reply
                0
                • O Offline
                  O Offline
                  oBOXPOH
                  wrote on last edited by
                  #8

                  Comrades! What I have got:

                  WaitingDialog dlg(this); //this - some custom widget
                  dlg.show();
                  
                  // some code (without other dialogs)
                  

                  I delete dlg.close(), but there is changed nothing.

                  WaitingDialog dlg = new WaitongDialog;
                  dlg->show();
                  
                  // some code
                  

                  I create dialog without parent and just show this dialog. In the beginning of execution (when Qt calls dialog) I see the dialog only with title, but when the execution of some code finished (I'm not close dlg (dlg->close()), the content of the dialog became visible.

                  In code I don't call to dialogs, just compute some values.

                  Strangely!

                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Hi,

                    Can you show the complete method code where you create that dialog ?

                    O Offline
                    O Offline
                    oBOXPOH
                    wrote on last edited by oBOXPOH
                    #9

                    @SGaist said in QDialog don't show widgets, when method show() calling:

                    Hi,

                    Can you show the complete method code where you create that dialog ?

                    Code of the dialog:

                    WaitingDialog::WaitingDialog(QWidget *parent) :
                        QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
                    {
                        mainLayout = new QHBoxLayout;
                    
                        textLabel = new QLabel(tr("Processing..."));
                        mainLayout->addWidget(textLabel);
                    
                        setLayout(mainLayout);
                    
                        setWindowTitle(tr("Waiting"));
                    }
                    
                    WaitingDialog::~WaitingDialog(){}
                    

                    Code of the method:

                    {
                        ...
                    
                        WaitingDialog *dlg = new WaitingDialog;
                        dlg->show();
                        Sleep(10000);
                    }
                    

                    In the beginning the dialog show only title. After 10 seconds I get management of parent (where I use this code) and content of the dialog (QLabel) in this dialog. I.e. get content only after Sleep!

                    1 Reply Last reply
                    0
                    • Vinod KuntojiV Offline
                      Vinod KuntojiV Offline
                      Vinod Kuntoji
                      wrote on last edited by
                      #10

                      @oBOXPOH ,

                      What are you executing?

                      C++, Qt, Qt Quick Developer,
                      PthinkS, Bangalore

                      O 1 Reply Last reply
                      0
                      • Vinod KuntojiV Vinod Kuntoji

                        @oBOXPOH ,

                        What are you executing?

                        O Offline
                        O Offline
                        oBOXPOH
                        wrote on last edited by
                        #11

                        @Vinod-Kuntoji said in QDialog don't show widgets, when method show() calling:

                        @oBOXPOH ,

                        What are you executing?

                        Code of the method:
                        
                        {
                            ...
                        
                            WaitingDialog *dlg = new WaitingDialog;
                            dlg->show();
                            Sleep(10000);
                        }
                        
                        
                        D 1 Reply Last reply
                        0
                        • O oBOXPOH

                          @Vinod-Kuntoji said in QDialog don't show widgets, when method show() calling:

                          @oBOXPOH ,

                          What are you executing?

                          Code of the method:
                          
                          {
                              ...
                          
                              WaitingDialog *dlg = new WaitingDialog;
                              dlg->show();
                              Sleep(10000);
                          }
                          
                          
                          D Offline
                          D Offline
                          Devopia53
                          wrote on last edited by
                          #12

                          @oBOXPOH

                          Never use the Sleep(). This is because the currently executing thread(aka. GUI) is blocking.

                          like this:

                          WaitingDialog *dlg = new WaitingDialog(this);
                          QTimer::singleShot(10000, [=, dlg]{ 
                              /* Manage what you want here. */
                              dlg->deleteLater(); 
                          });
                          dlg->setModal(true);
                          dlg->show();
                          
                          O 1 Reply Last reply
                          1
                          • Vinod KuntojiV Offline
                            Vinod KuntojiV Offline
                            Vinod Kuntoji
                            wrote on last edited by
                            #13

                            @oBOXPOH ,

                            Are you showing dialog inside thread?

                            C++, Qt, Qt Quick Developer,
                            PthinkS, Bangalore

                            O 1 Reply Last reply
                            0
                            • D Devopia53

                              @oBOXPOH

                              Never use the Sleep(). This is because the currently executing thread(aka. GUI) is blocking.

                              like this:

                              WaitingDialog *dlg = new WaitingDialog(this);
                              QTimer::singleShot(10000, [=, dlg]{ 
                                  /* Manage what you want here. */
                                  dlg->deleteLater(); 
                              });
                              dlg->setModal(true);
                              dlg->show();
                              
                              O Offline
                              O Offline
                              oBOXPOH
                              wrote on last edited by
                              #14

                              I used Sleep() as example. If instead of Sleep() I want compute something during showing dialog, what can I do?

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                Except that you will block the main thread and thus your dialog will not show until its too late.

                                If you have a long computational process running you should consider maybe using QtConcurrent and wire that properly with your GUI.

                                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
                                2
                                • Vinod KuntojiV Vinod Kuntoji

                                  @oBOXPOH ,

                                  Are you showing dialog inside thread?

                                  O Offline
                                  O Offline
                                  oBOXPOH
                                  wrote on last edited by
                                  #16

                                  @Vinod-Kuntoji said in QDialog don't show widgets, when method show() calling:

                                  @oBOXPOH ,

                                  Are you showing dialog inside thread?

                                  I show dialog, when something button was clicked. During this dialog some computing task must execute. When this task finish, this dialog must close.

                                  1 Reply Last reply
                                  0
                                  • Vinod KuntojiV Offline
                                    Vinod KuntojiV Offline
                                    Vinod Kuntoji
                                    wrote on last edited by
                                    #17

                                    @oBOXPOH ,

                                    Are you talking about progressbar?

                                    C++, Qt, Qt Quick Developer,
                                    PthinkS, Bangalore

                                    O 1 Reply Last reply
                                    0
                                    • Vinod KuntojiV Vinod Kuntoji

                                      @oBOXPOH ,

                                      Are you talking about progressbar?

                                      O Offline
                                      O Offline
                                      oBOXPOH
                                      wrote on last edited by
                                      #18

                                      @Vinod-Kuntoji said in QDialog don't show widgets, when method show() calling:

                                      @oBOXPOH ,

                                      Are you talking about progressbar?

                                      Just about some dialog with text without any buttons. If it easier for you, yes, about progressbar.

                                      mrjjM 1 Reply Last reply
                                      0
                                      • O oBOXPOH

                                        @Vinod-Kuntoji said in QDialog don't show widgets, when method show() calling:

                                        @oBOXPOH ,

                                        Are you talking about progressbar?

                                        Just about some dialog with text without any buttons. If it easier for you, yes, about progressbar.

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

                                        Hi

                                        • Just about some dialog with text without any buttons. If it easier for you, yes, about progressbar.

                                        Its not so much about being easier.
                                        Its a concrete class
                                        http://doc.qt.io/qt-5/qprogressbar.html

                                        Also
                                        WaitingDialog *dlg = new WaitingDialog;
                                        dlg->show();
                                        Sleep(10000); <<< here u lag all of application. nothing can be drawn and u will first see dialog after 10 secs.

                                        Sleep cannot be used to simulate a workload.

                                        O 1 Reply Last reply
                                        1
                                        • mrjjM mrjj

                                          Hi

                                          • Just about some dialog with text without any buttons. If it easier for you, yes, about progressbar.

                                          Its not so much about being easier.
                                          Its a concrete class
                                          http://doc.qt.io/qt-5/qprogressbar.html

                                          Also
                                          WaitingDialog *dlg = new WaitingDialog;
                                          dlg->show();
                                          Sleep(10000); <<< here u lag all of application. nothing can be drawn and u will first see dialog after 10 secs.

                                          Sleep cannot be used to simulate a workload.

                                          O Offline
                                          O Offline
                                          oBOXPOH
                                          wrote on last edited by
                                          #20

                                          @mrjj said in QDialog don't show widgets, when method show() calling:

                                          Hi

                                          • Just about some dialog with text without any buttons. If it easier for you, yes, about progressbar.

                                          Its not so much about being easier.
                                          Its a concrete class
                                          http://doc.qt.io/qt-5/qprogressbar.html

                                          Also
                                          WaitingDialog *dlg = new WaitingDialog;
                                          dlg->show();
                                          Sleep(10000); <<< here u lag all of application. nothing can be drawn and u will first see dialog after 10 secs.

                                          Sleep cannot be used to simulate a workload.

                                          I know! I wrote Sleep() only for example. But even in this case dlg->show() doesn't show content of the dialog, shows only title and window.

                                          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