Kemarin bingung, nyari gimana caranya nyambungin slot yang uda dibikin ke komponen guinya kalo pakai qtcreator, setelah searching, nemu postingan maknyus dari thejim di http://www.qtcentre.org/threads/28335-QT-Creator-won-t-recognize-a-slot
Langkah-langkah untuk menambahkannya:
To add a custom slot for a button:
-
Switch to signal/slot edit mode (F4).
-
Click and drag on the button to initiate the signal/slot editor.
-
In the left pane, select your “clicked()”/”triggered()”/whatever signal.
-
Below the right pane, click the “edit” button.
-
Below the top pane, click the “Add” button, and enter the call for your custom slot.
-
Click OK, and your custom slot should now be in the right pane.
-
Select your custom slot, click OK, and build your project.
After you do this, the slot will show up in the <slots> drop-down, but since a signal/slot connection is created for you at this point, you’ll only need to utilize it from the drop-down if you use it with another signal.
Ignore: Unfortunately, this doesn’t work for menus, since the signals/slots edit mode wants to attach to the menu bar, rather than the menu items. If anyone has a workaround for this, I’d greatly appreciate it…
EDIT:
There is an easy trick to getting Creator to automatically connect signals to your custom slots, regardless of what they are: You have to name the slot function appropriately.
You have to name them using the format “on_<sender object name>_<signal>”. For example, if you have a button named “calculateButton”, and you want to launch your calculate function via the “clicked()” signal, you must name your function: “on_calculateButton_clicked”.
Qt Code:
Switch view
-
void on_calculateButton_clicked();
To copy to clipboard, switch view to plain text mode
Note that if you’re hand-coding everything, this doesn’t matter, you can name your slots and functions whatever you want. But to make it easier when working in Creator, using this naming convention for slots makes it less of a headache.