[UI] Connection between QAction and SLOT
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...) ?
Paste more code. What type is Ui_MainWindow? Where you declare actions? This could be a problem with include(missing include) or not. Hard to say without a context.
If you want create menu by yourself you must create an action and then bin them with Slot and menu item.
Something like that:
newAction = new QAction(tr("&New"), this);
newAction->setStatusTip(tr("Create a new spreadsheet file"));
connect(newAction, SIGNAL(triggered()), this, SLOT(newFile()));
adding menu item
fileMenu = menuBar()->addMenu(tr("&File"));
but if you want use already created Actions:
@connect(ui->actionName, SIGNAL(triggered()), this, SLOT(on_triggered()));
Thanks a lot qxoz, I'll create the entire interface including the menu item.
If I have some problems, I'll post them in this post...