Are lambda signals and slots handled by moc
-
I asked GPT3, and it said NO, with this as an example
GPT:
QObject::connect(sender, &Sender::signalName, this, [](int value) { qDebug() << "Lambda slot called with value:" << value; });In this example, the lambda function is used as a slot directly with the
QObject::connectsyntax. The connection is made using the pointer-to-member-function syntax (&Sender::signalName) instead of using the old-styleSIGNALandSLOTmacrosIn summary, lambda functions used as signals and slots in Qt are not handled by the MOC. They provide a modern and efficient way of connecting signals and slots in your application without the need for MOC-generated code.
-
I asked GPT3, and it said NO, with this as an example
GPT:
QObject::connect(sender, &Sender::signalName, this, [](int value) { qDebug() << "Lambda slot called with value:" << value; });In this example, the lambda function is used as a slot directly with the
QObject::connectsyntax. The connection is made using the pointer-to-member-function syntax (&Sender::signalName) instead of using the old-styleSIGNALandSLOTmacrosIn summary, lambda functions used as signals and slots in Qt are not handled by the MOC. They provide a modern and efficient way of connecting signals and slots in your application without the need for MOC-generated code.
Moc is only needed for old-styled connect(), introspection and qml integration.
-
T Tahar has marked this topic as solved on
-
Moc is only needed for old-styled connect(), introspection and qml integration.
@Christian-Ehrlicher
Thanks for the response, is there a source where I can read more about this? -
@Christian-Ehrlicher
Thanks for the response, is there a source where I can read more about this? -
@Christian-Ehrlicher
Is moc required toqobject_cast<>to yourQ_OBJECTclasses?And it says there it's required for
tr()which affects many coders. -
@Christian-Ehrlicher
Is moc required toqobject_cast<>to yourQ_OBJECTclasses?And it says there it's required for
tr()which affects many coders.@JonB said in Are lambda signals and slots handled by moc:
Is moc required to qobject_cast<> to your Q_OBJECT classes?
Yes since qobject_cast<> is using stuff generated by moc (the metaobject name)
And it says there it's required for tr() which affects many coders.
This would be new to me.
lupdate fetches the strings by parsing the source code, not some moc stuff. The context comes from the class name. You could take a look into the generated moc file to see if there is something wrt translation. -
@JonB said in Are lambda signals and slots handled by moc:
Is moc required to qobject_cast<> to your Q_OBJECT classes?
Yes since qobject_cast<> is using stuff generated by moc (the metaobject name)
And it says there it's required for tr() which affects many coders.
This would be new to me.
lupdate fetches the strings by parsing the source code, not some moc stuff. The context comes from the class name. You could take a look into the generated moc file to see if there is something wrt translation.@Christian-Ehrlicher
Your https://doc.qt.io/qt-6/metaobjects.html listed:In addition to providing the signals and slots mechanism for communication between objects (the main reason for introducing the system), the meta-object code provides the following additional features:
QObject::tr()translates strings for internationalization.