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
Forum Updated to NodeBB v4.3 + New Features

Qml signal doesn't take effect

Scheduled Pinned Locked Moved QML and Qt Quick
qmlsignals emit
4 Posts 3 Posters 1.7k 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 14 Sept 2015, 18:49 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

    P 1 Reply Last reply 15 Sept 2015, 10:05
    0
    • T tootis
      14 Sept 2015, 18:49

      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

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 15 Sept 2015, 10:05 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 15 Sept 2015, 15:48
      0
      • P p3c0
        15 Sept 2015, 10:05

        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 15 Sept 2015, 15:48 last edited by
        #3

        @p3c0 Yes

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kolegs
          wrote on 16 Sept 2015, 07:43 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

          1/4

          14 Sept 2015, 18:49

          • Login

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