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
    #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
                            • mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #21

                              @oBOXPOH

                              Ok, but you description of your issue , sounds 100% when a poster loop/sleep the main thread and
                              other windows shows up as empty becuase there is no time to draw the child widgets.

                              dlg->show() doesn't show content of the dialog, shows only title and window.

                              Well do you call a loop or something else after you open the dialog ?

                              Clearly
                              WaitingDialog *dlg = new WaitingDialog;
                              dlg->show();

                              must work and i assume the widget IN the dialog is made with UI file so all should be ok ?

                              There is something you are not telling :)

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

                                @oBOXPOH ,

                                WaitingDialog *dlg = new WaitingDialog;
                                dlg->exec();

                                connect(dlg,SIGNAL(aborted()),dlg,SLOT(stopDialog()));
                                connect(yourWidget,SIGNAL(executionComplete()),dlg,SLOT(stopDialog()));

                                void WaitingDialog::stopDialog() {
                                this->close();
                                emit aborted();
                                }

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

                                O 1 Reply Last reply
                                1
                                • Vinod KuntojiV Vinod Kuntoji

                                  @oBOXPOH ,

                                  WaitingDialog *dlg = new WaitingDialog;
                                  dlg->exec();

                                  connect(dlg,SIGNAL(aborted()),dlg,SLOT(stopDialog()));
                                  connect(yourWidget,SIGNAL(executionComplete()),dlg,SLOT(stopDialog()));

                                  void WaitingDialog::stopDialog() {
                                  this->close();
                                  emit aborted();
                                  }

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

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

                                  @oBOXPOH ,

                                  WaitingDialog *dlg = new WaitingDialog;
                                  dlg->exec();

                                  connect(dlg,SIGNAL(aborted()),dlg,SLOT(stopDialog()));
                                  connect(yourWidget,SIGNAL(executionComplete()),dlg,SLOT(stopDialog()));

                                  void WaitingDialog::stopDialog() {
                                  this->close();
                                  emit aborted();
                                  }

                                  It seems logical. I'll try. Thanks!

                                  1 Reply Last reply
                                  0
                                  • VRoninV Offline
                                    VRoninV Offline
                                    VRonin
                                    wrote on last edited by VRonin
                                    #24

                                    I'll say what everybody else is afraid to say. Because this is not the solution Gotham deserves but it's the one it needs right now:
                                    just add QApplication::processEvents(); after dlg.show();

                                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                    ~Napoleon Bonaparte

                                    On a crusade to banish setIndexWidget() from the holy land of Qt

                                    mrjjM O 2 Replies Last reply
                                    3
                                    • VRoninV VRonin

                                      I'll say what everybody else is afraid to say. Because this is not the solution Gotham deserves but it's the one it needs right now:
                                      just add QApplication::processEvents(); after dlg.show();

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

                                      @VRonin
                                      hehe first time i seen the evil QApplication::processEvents() served with a batman quote :))

                                      1 Reply Last reply
                                      0
                                      • VRoninV VRonin

                                        I'll say what everybody else is afraid to say. Because this is not the solution Gotham deserves but it's the one it needs right now:
                                        just add QApplication::processEvents(); after dlg.show();

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

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

                                        I'll say what everybody else is afraid to say. Because this is not the solution Gotham deserves but it's the one it need right now:
                                        just add QApplication::processEvents(); after dlg.show();

                                        It's working! Thanks a lot! Great!

                                        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