tags:

views:

445

answers:

2

I am completely new to Qt.

I started with a new Qt4 GUI Application.

Using the designer, I have created a menu like so:

File
 - Exit

How do I get an action associated with the menu item?

I found something called the 'Signals and slots editor' but have no idea how to use it.

+2  A: 

Click on the green plus sign after you selected the signals Slots Editor. It will give you 4 fields to fill in. For sender you select what is creating the signal. For example ActionExit might be the name you created for the exit menu item. The signal is probably going to be clicked(). The receiver is usually the class that you created that has all of your methods. The slot is the method you created in that class that you want to execute. For example:

actionExit clicked() exitGame()

Hope this helps.

Isawpalmetto
Okay, great. One more quick question... what is the method signature for the function that gets called when the menu item is clicked? Is it like `void OnClick()`, or are there arguments to it?
George Edison
Actually you would want to select triggered() because since it is an action. Now for the method that gets called, it does not need any arguments so you could call it void exitGame() if you want.
Isawpalmetto
By the way, I forgot to mention that triggered() is what should go in the signal field. Just wanted to be clear.
Isawpalmetto
Okay, I have files `mainwindow.cpp` and `mainwindow.h`. I added a `void` function but it won't show up in the slot field when I select `MainWindow` as the receiver... any ideas?
George Edison
did you add it to the slots in the mainWindow.h file?
Isawpalmetto
@lsawpalmetto: Sorry, add it to the slots? How do I do that?
George Edison
In the .h file you can add the data members and any slots. Check out some examples on the QT site, but it's basically like this:private slots: void exitGame();Ant then in the mainWindow.cpp file you can write the method for exitGame()
Isawpalmetto
A: 

I managed to do this in a way that seems much easier. In the Qt Creator Action Editor window, i see an entry for the menu item I clicked. I rt-click that entry and select "Go to slot..." then i select triggered() from the popup and click OK. Qt Creator jumps me to the code it just added.... I put a qDebug statement in there and it works!