QDialog/QWidget is closing after init
-
Here is the main file that creates a
Appobject calledw.int main(int argc, char *argv[]) { QApplication a(argc, argv); App w; w.show(); return a.exec(); }Here is the
Appinitialization, 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
PlotQDialog 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.
-
Here is the main file that creates a
Appobject calledw.int main(int argc, char *argv[]) { QApplication a(argc, argv); App w; w.show(); return a.exec(); }Here is the
Appinitialization, 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
PlotQDialog window is closing after theshow()method? -
Watch out, you are blocking your application until you close your dialog. Is that really what you want ?