Qt World Summit: Register Today!

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

  • 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

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

  • where I call exec:

    	d_sequencer = new Dsequencer(this);
    	delete d_sequencer;

    the redefinited exec:

    int Dsequencer::exec()
    	ui->pB_show_times_page->setStyleSheet (SET_COLOR_BUTTON);
    	ui->pB_show_set_type_page->setStyleSheet (UNSET_COLOR_BUTTON);
    	return QDialog::exec();

    thank you

  • @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)

  • Lifetime Qt Champion

    Hi and welcome to devnet,

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

  • @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);
    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 ... :)

  • Lifetime Qt Champion

    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.

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

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

  • Lifetime Qt Champion

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

Log in to reply