I saw 2, maybe 3 questions of this kind in this wonderful forum, but they are all very confusing, there is no need to go to the creator of the signal / slot that Qt Designer just received, and follow these steps
1.add Menu and action in the menu bar and add any function to the slot of your mainwindow.h file as the following private slots: void help();
2. Secondly, add the following code to your mainwindow.cpp.
connect(ui->actionmyactions, SIGNAL(triggered()), this, SLOT(help()));
3. The same can be done for the menu using the following code:
connect(ui->menuHelp, SIGNAL(aboutToShow()), this, SLOT(help()));
4. You can get the desired results without going to Qt Designer as follows.
declare your action in mainwindow.h as follows
QAction *myaction;
and add the following code to your mainwindow.cpp
myaction = ui->mainToolBar->addAction("help"); connect(myaction, SIGNAL(triggered()), this, SLOT(help()));
Shaikh Chili Jun 27 '19 at 9:37 2019-06-27 09:37
source share