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. How do I create a handler for a signal from my c++ object?
Forum Updated to NodeBB v4.3 + New Features

How do I create a handler for a signal from my c++ object?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 561 Views 1 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.
  • K Offline
    K Offline
    kgregory
    wrote on 30 Jun 2017, 04:31 last edited by kgregory
    #1

    My QtQuick application is initialized as shown below from c++ main(). I have a signal from myObject, that I wish to handle in the QML pages but I can't figure out how. The last part of this guide (http://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html) touches on it, but doesn't work for me. I think it may be because the object is created from main() and not from within the QML.

        MyObjectType myObject;
        QQuickView *view = new QQuickView;
        view->rootContext()->setContextProperty("myObject", &myObject);
        view->setSource(QUrl("qrc:/main.qml"));
        view->setResizeMode(QQuickView::SizeRootObjectToView);
        view->show();
    

    Here is one thing I tried within my main QML item. I tried a bunch of other things too, but now I'm stumped. This gives me the warning 'Cannot assign to non-existent property "ghoztConnecting"' on the second line.

        signal signalToHandle()
        signalToHandle: myObject.onMySignal()
        onSignalToHandle: {
        pageLoader.source="home.qml";
        }
    

    I've also tried simply this, but it seems like it only recognizes the reference to myObject within the javascript code regions.

    myObject.onMySignal: {
        pageLoader.source="home.qml";
        }
    

    Any suggestions?

    R 1 Reply Last reply 30 Jun 2017, 06:09
    0
    • K kgregory
      30 Jun 2017, 04:31

      My QtQuick application is initialized as shown below from c++ main(). I have a signal from myObject, that I wish to handle in the QML pages but I can't figure out how. The last part of this guide (http://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html) touches on it, but doesn't work for me. I think it may be because the object is created from main() and not from within the QML.

          MyObjectType myObject;
          QQuickView *view = new QQuickView;
          view->rootContext()->setContextProperty("myObject", &myObject);
          view->setSource(QUrl("qrc:/main.qml"));
          view->setResizeMode(QQuickView::SizeRootObjectToView);
          view->show();
      

      Here is one thing I tried within my main QML item. I tried a bunch of other things too, but now I'm stumped. This gives me the warning 'Cannot assign to non-existent property "ghoztConnecting"' on the second line.

          signal signalToHandle()
          signalToHandle: myObject.onMySignal()
          onSignalToHandle: {
          pageLoader.source="home.qml";
          }
      

      I've also tried simply this, but it seems like it only recognizes the reference to myObject within the javascript code regions.

      myObject.onMySignal: {
          pageLoader.source="home.qml";
          }
      

      Any suggestions?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 30 Jun 2017, 06:09 last edited by
      #2

      @kgregory
      you need to go this way via the Connections element in QML:

      Connections {
          target: myObject
          onMySignal: {
             pageLoader.source="home.qml";
          }
      }
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2

      2/2

      30 Jun 2017, 06:09

      • Login

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