PDA

View Full Version : Create signal/slots in runtime ?



nbilber
30th October 2015, 11:14
Hi,

It's possible to create/generate signals and slots in runtime (not compile time) ?

Regards,
Thanks

Lesiok
30th October 2015, 12:18
What does it mean "create/generate signals and slots in runtime" ?

anda_skoa
30th October 2015, 12:20
Don't think so, but maybe we are not thinking about the same thing.
What is it that you are trying to achieve?

Cheers,
_

nbilber
30th October 2015, 14:24
Well

Example I have an empty grilayout and receive a file to build ui by code.
So I create an new QCombobox() and set values.
Next I want to define a signal ex, changeCurrentIndex() and then generate a slot() dynamically, slot1(), slot2(), ...slotn()
Can I generate a callback slot for that ?

Cheers

anda_skoa
30th October 2015, 16:38
You could have one slot and identify the sender using QObject::sender(), or have a dedicated receiver object for each row.

Cheers,
_

nbilber
30th October 2015, 18:00
But I have previous in compile time define *.cpp code for that slot ?

Thanks

ChrisW67
30th October 2015, 19:32
The actions performed by a slot, which is just another class function not some magical entity, have to be compiled into a code unit somewhere. You cannot do that at runtime for C++. You can, of course, connect existing signals and slots at runtime. If the range of behaviours to be performed by the slotn() functions is known then you can pre-build them and connect at runtime if they are needed.

Beyond that, it sounds like you want some sort of plugin that can provide a widget and associated processing logic. Qt has a plugin mechanism you can use.