P
P
Pavel2014-08-20 12:13:43
Qt
Pavel, 2014-08-20 12:13:43

Which method tells the QWidget not to disappear after being displayed by the show() method?

I create a new QWidget window from the main window class, when I click the corresponding item in the menu, the Qwidget window is displayed and immediately closes, how can I fix this? I call like this

OptionApp OptionDialog;
OptionDialog.show();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
EXL, 2014-08-20
@yankeenoobs

You are doing something wrong.
In this case, you create an object of the OptionApp class on the stack, which means that after the function exits, it will be destroyed. Correct to

OptionApp *optionDialog = new OptionApp(this);
optionDialog->show();

And don't forget to call in the widget class constructor of this window:
To avoid a memory leak.
This is if you need a non-modal dialog. Otherwise, just use
the method:
OptionDialog.exec();

X
xseven, 2014-08-20
@xseven

You create a modeless dialog by calling show()
If I understand correctly, then:
Try calling exec() instead of show(), then the window will become modal and will not close until you complete the necessary actions in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question