#include class MyMainWindow : public QMainWindow { Q_OBJECT public: MyMainWindow() : QMainWindow() {} public slots: void openDialog(); }; void MyMainWindow::openDialog() { QDialog* childWindow = new QDialog(); QVBoxLayout* l = new QVBoxLayout(); childWindow->setLayout(l); QPushButton* button = new QPushButton("Close", childWindow); connect(button, SIGNAL(clicked(bool)), childWindow, SLOT(close())); l->addWidget(button); childWindow->show(); } int main(int argc, char* argv[]) { QApplication app(argc, argv); MyMainWindow* mainWindow = new MyMainWindow(); QMenu* fileMenu = mainWindow->menuBar()->addMenu("File"); fileMenu->addAction("Open Dialog", mainWindow, SLOT(openDialog())); mainWindow->show(); app.exec(); } #include "menuBarTest.moc"