Solved QDialog/QWidget is closing after init
-
Here is the main file that creates a
App
object calledw
.int main(int argc, char *argv[]) { QApplication a(argc, argv); App w; w.show(); return a.exec(); }
Here is the
App
initialization, where I create another window usingQDialog
. The name of this class isPlot
.App::App(QWidget *parent) : QMainWindow(parent) , ui(new Ui::App) { ui->setupUi(this); Plot p(this); p.setModal(true); p.show(); ... }
Why the
Plot
QDialog window is closing after theshow()
method? -
Hi,
Because the variable p is on the stack and is local to the constructor. The show method being not blocking and the constructor ending after the call to show, p is destroyed immediately.
-
@fem_dev
I found:p.exec();
-
NOPE! do not block the execution of constructors,
App
would live in a dangerous limbo if you do that -
Watch out, you are blocking your application until you close your dialog. Is that really what you want ?
-
Sorry guys...you two are right...
I'm doing this wrong...
thanks!