jeudi 20 juillet 2017

Qt: QObject::connect signal by name to lambda

there are two types of signal/slot connection semantics in Qt:

connect(sender, SIGNAL(mySignal()), receiver, SLOT(mySlot())); // 1
connect(sender, &MySender::mySignal, receiver, &MyReceiver::mySlot); // 2

2 is usually preferable and supports connections to lambda functions. When object type is not defined at compile-time, 1 is the only option. Working with QtQuick objects from c++ is exactly this case.

Is there a way to connect signal by name to lambda function? Something like

connect(sender, SIGNAL(mySignal()), receiver, [] { ... });

Aucun commentaire:

Enregistrer un commentaire