Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qml signal doesn't take effect

Qml signal doesn't take effect

Scheduled Pinned Locked Moved QML and Qt Quick
qmlsignals emit
4 Posts 3 Posters 2.0k Views 2 Watching
  • 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 Offline
    T Offline
    tootis
    wrote on last edited by tootis
    #1

    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

    p3c0P 1 Reply Last reply
    0
    • T 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

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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
      0
      • p3c0P p3c0

        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");

        T Offline
        T Offline
        tootis
        wrote on last edited by
        #3

        @p3c0 Yes

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kolegs
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved