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::exec does not show the window but the input is ok

QDialog::exec does not show the window but the input is ok

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 3.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.
  • G Offline
    G Offline
    giancgianc
    wrote on last edited by A Former User
    #1

    In my program I show a QDialog from a button, with a redefined exec function, at the end of function I call QDialog::exec.
    Sometime the dialogue does not appear.
    The strange thing is that the input it works, if I press the enter key, the code connected at the button that has the focus, in the hidden dialog, is executed.
    The under dialog, that I see, does not receive the input.
    I compiled the program in the debug version, but I can not go inside QDialog :: exec source.
    Maybe I need to specify a few options?
    Thank for your help

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

      Did you assign a parent to the Dialog?
      Could you show us your code?

      "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

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giancgianc
        wrote on last edited by VRonin
        #3

        where I call exec:

        	d_sequencer = new Dsequencer(this);
        	d_sequencer->exec();
        	delete d_sequencer;
        

        the redefinited exec:

        
        int Dsequencer::exec()
        {
        	ui->sW_pages->setCurrentIndex(0);
        	ui->pB_show_times_page->setStyleSheet (SET_COLOR_BUTTON);
        	ui->pB_show_set_type_page->setStyleSheet (UNSET_COLOR_BUTTON);
        ...
        ....
        	return QDialog::exec();
        }
        

        thank you

        VRoninV 1 Reply Last reply
        0
        • G giancgianc

          where I call exec:

          	d_sequencer = new Dsequencer(this);
          	d_sequencer->exec();
          	delete d_sequencer;
          

          the redefinited exec:

          
          int Dsequencer::exec()
          {
          	ui->sW_pages->setCurrentIndex(0);
          	ui->pB_show_times_page->setStyleSheet (SET_COLOR_BUTTON);
          	ui->pB_show_set_type_page->setStyleSheet (UNSET_COLOR_BUTTON);
          ...
          ....
          	return QDialog::exec();
          }
          

          thank you

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          @giancgianc said in QDialopg::exec does not show the window but the input is ok:

          d_sequencer = new Dsequencer(this);

          what is this? Try removing it (i.e. making it top level dialog) or passing parent() instead (i.e. making it sibling of this)

          "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

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

            Hi and welcome to devnet,

            Out of curiosity, why do you do initialisation related stuff in exec rather than in your class constructor ?

            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
            0
            • G Offline
              G Offline
              giancgianc
              wrote on last edited by
              #6

              @VRonin
              'this' is

              DextraFunctionsMenu::DextraFunctionsMenu(QWidget *parent) :
              QDialog(parent),ui(new Ui::DextraFunctionsMenu)

              and I call exec in a QButton onClick event

              void DextraFunctionsMenu::on_pB_sequencer_clicked()
              {
              d_sequencer = new Dsequencer(this);
              d_sequencer->exec();
              delete d_sequencer;
              }
              I tried with NULL but no change, I will try with parent() but (I think) its the same.

              @SGaist , because in a first version of the code I used 'show' and I created all the dialogs when the application starts, then the code has remained so.

              Thak you, and sorry for my english ... :)

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

                Even in the show method. Widget construction related code has its place more in the constructor than in show or exec. One might arg that some of the Qt example use helper functions to separate the different steps of the widget construction but they are still all called in the widget constructor.

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

                G 1 Reply Last reply
                1
                • SGaistS SGaist

                  Even in the show method. Widget construction related code has its place more in the constructor than in show or exec. One might arg that some of the Qt example use helper functions to separate the different steps of the widget construction but they are still all called in the widget constructor.

                  G Offline
                  G Offline
                  giancgianc
                  wrote on last edited by
                  #8

                  @SGaist, true, but, before, I not destroyed the object, I re-used it and I needed to reset it

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    stryga42
                    wrote on last edited by
                    #9

                    Maybe the stacking order of your windows and dialogs is somehow messed up and you just can't see the dialog because it is hidden by another window. Creating it with a nullptr parent should place it always on top but in your app a lot happens between creation and exec, as I understand. Try an explicit QWidget::raise before you exec.

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

                      @giancgianc In that case you should make that explicit. Have a reset function that you call before exec if you really are re-using that widget.

                      Note that in your code sample you are not re-using the widget pointed to by d_sequencer since you delete after the call to exec. So it really does make sense to use a local on stack variable thus move the initialisation code in the constructor.

                      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
                      0

                      • Login

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