[UI] Connection between QAction and SLOT
Hi everybody,
I’ve already made a Qt UI with Qt Designer and I got a menu bar with File menu (New File, Open File, Save File, Quit).
My wish is to connect the Quit action when its triggered to quit … I tried the command
- connect(Ui_MainWindow.actionQuit, SIGNAL(triggered()), this, SLOT(close()));
in the constructor of MainWindow but i got this error message :
- ..\mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
- ..\mainwindow.cpp:10: error: expected primary-expression before '.' token
I don’t really understand this error …
So I tried with the UI connection action (“go to slot”) it works but i just want to know if it’s possible to make this connection and if it is possible how (because with the ui connection action, i will get too much functions…) ?
4 replies
If you want create menu by yourself you must create an action and then bin them with Slot and menu item.
Something like that:
- void MainWindow::createActions()
- {
- newAction->setShortcut(tr("Ctrl+N"));
- newAction->setStatusTip(tr("Create a new spreadsheet file"));
- connect(newAction, SIGNAL(triggered()), this, SLOT(newFile()));
adding menu item
- fileMenu = menuBar()->addMenu(tr("&File"));
- fileMenu->addAction(newAction);
You must log in to post a reply. Not a member yet? Register here!


