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

1

6

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?

Purcell answered 11/5, 2017 at 14:20 Comment(0)
P
8

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.

Phallicism answered 11/5, 2017 at 14:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.