Adding an action listener to QT jambi is a little bit different then adding one in regular java. The first and major difference is the absence of an inner class which overrides the actionEvent method inside the action listener class, QT actually accepts string arguments of the method name to call an action listener. So in this case, technically any method can become an action listener. This allows for a greater amount of flexibility and customization when it comes to action listeners in QT.
There are a couple different terms that you need to know about as well when it comes to adding a QT action listener to your code.
Triggered:
When a QAction is created in QT, per say to go into a menu bar to perform something, is clicked… The QSignalEmitter sends off a triggered signal. This is the action listener call you want to keep in mind when taking care of QAction’s from menu bars and toolbars.
Clicked:
This one is pretty straight forward. The clicked keyword is used when a QButton is created. This is to determine if the button was clicked, when the button is clicked, the QSignalEmitter will send a clicked signal.
Connect:
Connect is a keyword used on top of either triggered or clicked. This is used to connect the QSignalEmmiter to the method that will be handling the event as an “action listener”.
The general syntax that is used for a QT Jambi Action Listener is as follows…
1 2 | nameOfButton.clicked.connect(locationOfMethod, "methodName()"); nameOfQAction.triggered.connect(locationOfMethod, "methodName()"); |
The location of the method is this, if the method is in the current class. If it is not specify exactly where it is located so that it can find the method. Then the method name as a string. This will not respond with an error if you type the string in wrong so you will find out at run-time with an error if this has occurred. In this topic i only described both the triggered keyword as well as clickedt. However there are plenty more to choose from. Tutorials on those will come at a later point.
Cheers







