Qml signal doesn't take effect
-
Hi,
I've created a Qt Quick 2.5 app and connected signals and slots to my c++ module,
I only can send signals from c++ and activate QML slots, but I can't receive QML signals in c++here is my
main
:int main(int argc, char *argv[]) { QApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); AlfredApp(engine.rootObjects().first()); return app.exec(); }
here is my QML code which holds the signal:
MouseArea { id: mainButtonMouseArea objectName: "mainButtonMouseArea" anchors.fill: parent signal signalClicked() onClicked: { console.log("clicked") signalClicked() } }
I always get the console message from qml when I click on the MouseArea.
here is my c++ constructor:
AlfredApp::AlfredApp(QObject* viewRootObject, QObject* parent) : QObject(parent), d(new Private) { d->viewRootObject = viewRootObject; d->viewMainButton = viewRootObject->findChild<QObject*>("mainButton"); d->viewMainButtonIcon = viewRootObject->findChild<QObject*>("mainButtonIcon"); d->viewMainButtonMouseArea = viewRootObject->findChild<QObject*>("mainButtonMouseArea"); // Signals/Slots connection connect(d->viewMainButtonMouseArea, SIGNAL(signalClicked()), this, SLOT(mainButtonClicked())); connect(this, SIGNAL(signalListening()), d->viewMainButtonIcon, SLOT(listening())); connect(this, SIGNAL(signalProcessing()), d->viewMainButtonIcon, SLOT(processing())); }
Here is my slot that never gets called:
void AlfredApp::mainButtonClicked() { qDebug() << "Main Button Clicked"; }
BTW, there is some qml code that has slots/function that respond normally to C++ singals