Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
6.6.1
-
None
Description
#include <QGuiApplication> #include <QMetaObject> #include <QQmlApplicationEngine> class Handler : public QObject { Q_OBJECT public slots: void handle() { qDebug() << "received"; } }; auto findMetaMethod(QObject *object, const char *signature) -> QMetaMethod { const auto mo = object->metaObject(); return mo->method(mo->indexOfMethod(signature)); } int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.loadData(R"( import QtQuick Window { width: 200; height: 200; visible: true property alias value: mouse.value MouseArea { id: mouse anchors.fill: parent property bool value: false onClicked: { value = !value } Text { anchors.centerIn: parent text: mouse.value } } // onValueChanged: {} // existence of QML handler makes the C++ connection work } )"); const auto sender = engine.rootObjects().constFirst(); const auto signal = findMetaMethod(sender, "valueChanged()"); Handler handler; const auto slot = findMetaMethod(&handler, "handle()"); qDebug() << "signal" << signal.isValid(); qDebug() << "slot" << slot.isValid(); qDebug() << "connect" << !!QObject::connect(sender, signal, &handler, slot); return app.exec(); } #include "main.moc"
Here, I have tried to make connection between signal for aliased property in QML and C++ slot but the slot never invoked even though the returned connection object is truthy.
However, if I add any signal handler in QML, C++ slot suddenly works.
I have attached a webp which shows the problem.