QDialog/QWidget is closing after init
Solved
General and Desktop
-
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.
-
Watch out, you are blocking your application until you close your dialog. Is that really what you want ?