Menu bar items are action items. To do something when pressed, you need to catch the triggered() signal from the action. Read more about signals and slots here .
To do this, you need to declare a new slot in your MainWindow class. Qt also supports this automatically, without having to connect anything, but I prefer to do it myself. If you are not interested, just skip this part.
First we declare a new slot in your window class:
private slots: void clickMenuButton();
Then in your constructor you need to connect the triggered signal to your new slot:
connect(ui.actionObject, SIGNAL(triggered()), this, SLOT(clickMenuButton()));
The first argument is an object that contains the signal that we will listen to (menu button). The second is the name of the signal. The third is the object in which the receiving slot is located (in this case, our window). The fourth is the slot.
And also, clickMenuButton() will be called whenever an action is clicked.
As I said, Qt can also automatically connect signals to slots . The disadvantage here is that you cannot change the name of the slot, but you also do not need to connect it.
Qt Creator supports the creation of slots for widgets: if your menu acts, you should contact the form developer and you should see a list of actions in your form (if you do not, find the action editor). Right-click the action you want and click "Go" to the slot .... There, double-click triggered() .
Then Qt Creator will open a new slot in the code editor, and you can do whatever you want here!