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 send a signal with parameters from QML to cpp code
Forum Updated to NodeBB v4.3 + New Features

How do i send a signal with parameters from QML to cpp code

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 4.9k 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.
  • M Offline
    M Offline
    maxpayne
    wrote on last edited by
    #1

    Hi,

    I would appreciate some hints to this problem that I'm facing. I am creating dynamic components and would like to send some data back to the cpp code.

    (this is just pseudo code)
    in main.qml :

    @Rectangle {
    id: container

        MyComponent {
                 id: mycomp
             }
    

    }
    @
    in "MyComponent.qml"

    @Item {
    id: myitem

    var component = Qt.createComponent("Wheel.qml"); //dynamic objects...
     var object = component.createObject(myitem);
    

    }@

    finally "Wheel.qml"

    @ Rectangle {
    id:myWheel
    Component.onCompleted: {
    //SEND SOME DATA (x,y) TO CPP CODE
    }
    }@

    potential cpp code:
    @view->setSource(QUrl("qrc:/QML/main.qml"));
    QGraphicsObject *object = view->rootObject();
    ??@

    I am not sure how the how to send data as a signal from wheel component to cpp code. Any ideas?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Aleskey78
      wrote on last edited by
      #2

      "Using QML Bindings in C++ Applications":http://doc.trolltech.com/4.7-snapshot/qtbinding.html#calling-functions

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxpayne
        wrote on last edited by
        #3

        Thanks!

        Actually, it was this document that helped:

        http://doc.qt.nokia.com/latest/qml-extending-types.html#connecting-signals-to-methods-and-other-signals

        For dynamic objects use the connect call...

        So in "Wheel.qml"
        @Rectangle {
        id:myWheel
        Component.onCompleted: {
        //SEND SOME DATA (x,y) TO CPP CODE
        mySignal(x,y)
        }
        }@

        in “MyComponent.qml”

        @
        //the syntax is interesting here..you simply connect the signals but don't specify the arguments..
        object.mySignal.connect(myitem.anothersignal); @

        finally in cpp:

        @QGraphicsObject *object = view->rootObject();
        QObject::connect(object,SIGNAL(anothersignal(int,int)),this, SLOT(executeKClosure(int,int)));
        @

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Aleskey78
          wrote on last edited by
          #4

          no cpp detected..., only JS

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maxpayne
            wrote on last edited by
            #5

            I've updated my reply...the js code is crucial to propagate the data to the cpp code.

            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