Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Designer, missing "go to slot" in context menu?

I've been watching a Qt tutorial series on YouTube, in which the author shows how to call a function, when a button is pressed. He right-clicked on the button in Qt Creator IDE and chose "Go to slot", from where he chose the signal which would fire the generated function. Since I am used to develop with Netbeans, I simply tried to follow his example using the embedded Qt Designer. Unfortunately, there is no "Go to slot..." entry when I right-click on my button or any widget. I could, of course, create a new slot for my main window and then connect the button's signal to it, but doing it with a single function just seems way more convenient and clean to me. Is there a way to fix is, or if not, at least a way to do with via code entirely, without having to add a new slot to the main window for every single button that servers a different purpose? Thanks for your help.

like image 920
Byzantian Avatar asked Sep 01 '12 13:09

Byzantian


1 Answers

While I don't know why the QtDesigner in Netbeans doesn't provide this feature, I know what the feature does: It just creates a slot with a special name in your widget class. Note that it does not add a connect statement. It uses the automatic connection feature, which works like this:

For each slot which name matches this pattern:

void on_X_Y(...)

it will be connected to the signal named Y of the object named X. So if you have a QPushButton named button, and you want to handle the signal pressed, simply create a slot with the following signature:

void on_button_pressed()

If you wonder how this slot gets connected to the signal: This happens in the ui_...h file at the end of setupUi():

    QMetaObject::connectSlotsByName(WidgetName);
like image 51
leemes Avatar answered Nov 13 '22 22:11

leemes