Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qml signal doesn't take effect

    QML and Qt Quick
    qml signals emit
    3
    4
    1265
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tootis last edited by tootis

      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

      p3c0 1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators @tootis last edited by

        Hi @tootis and Welcome,

        Have you made sure that the exact object has been found ? I'm referring to this line:
        viewRootObject->findChild<QObject*>("mainButtonMouseArea");

        157

        T 1 Reply Last reply Reply Quote 0
        • T
          tootis @p3c0 last edited by

          @p3c0 Yes

          1 Reply Last reply Reply Quote 0
          • K
            kolegs last edited by

            Do you get any messages about slots/signals when connecting?(what I mean is "no such slot/signal")

            1 Reply Last reply Reply Quote 0
            • First post
              Last post