#ifndef DIALOG_H #define DIALOG_H #include #include #include #include #include #include #include #include class Dialog : public QDialog { Q_OBJECT public : Dialog(QWidget *parent = 0) : QDialog(parent) { QPushButton *b = new QPushButton("exec",this); QBoxLayout *l = new QBoxLayout(QBoxLayout::TopToBottom); l->addWidget(b); connect(b,SIGNAL(clicked()),this,SLOT(boom())); } protected slots : void boom() { hide(); QMessageBox::information(this,"Info","The application will now crash"); show(); } }; class MyWindow : public QMainWindow { Q_OBJECT public : MyWindow() { setCentralWidget(new QWidget(this)); QMenu *m = menuBar()->addMenu(tr("Actions")); QAction *a = m->addAction(tr("Dialog")); connect(a,SIGNAL(triggered()),this,SLOT(showMenu())); } public slots : void showMenu() { Dialog w(this); w.exec(); } }; #endif // DIALOG_H