Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signal to Slot in QT Creator, where is connect() function?

In QT Creator, design mode, I right-click on a widget and select "Go to slot" and it creates a slot function for one of the widget's signals. I would have thought that this would have generated a connect() function to create this connection, however, I can't find anything like that in any of the source code. Where is the actual code that connects the widget's signal to the slot function? thanks

like image 842
Eugene Barnett Avatar asked May 11 '17 14:05

Eugene Barnett


1 Answers

If you're using QtCreator's Designer, one of the outputs from this is a .ui file

Qt Designer ui files are an XML representation of your form's widget tree, and are processed by uic, the "User Interface Compiler"

One of the features provided by Qt's ui format is AutoConnect.

uic automatically generates code in the form's setupUi() function to connect your signals and slots.

The way it works is as follows:

Your slots must conform to the following format:

void on_<object-name>_<signal-name>(<signal-parameters>);

where object-name is the name of the object which emits the signal this slot is for.

Later, uic then generates code which calls QMetaObject::connectSlotsByName(this);

Using Qt's reflection system, the QObject which has objectName()=object-name is found, and it's signal is connected to your slot.

like image 171
Steve Lorimer Avatar answered Oct 18 '22 14:10

Steve Lorimer