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 can I pass a qml function (from qml file) as a parameter to c++ function ?

How can I pass a qml function (from qml file) as a parameter to c++ function ?

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 4 Posters 7.3k Views
  • 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.
  • A Offline
    A Offline
    aabc
    wrote on last edited by
    #1

    I want to pass a "callback" to a Q_INVOKABLE function i have on a C++ class.
    How can i pass as a callback a function which is in the qml file (the Q_INVOKABLE function is called from the qml file)

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Send a signal, and receive it in C++? I'm not sure I understand what you want to achieve.

      (Z(:^

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Punit_Tak
        wrote on last edited by
        #3

        this can be possible as sierdzio said, signal can be emitted from C++ this can be connected to with another signal using pointer of qml QObject .
        e.g.

        @Object::connect(this, SIGNAL(requestXyz()), m_qmlScreenObject, SIGNAL(requestXyzQML()));@

        and in QML

        @function xyz()
        { ... }

        onXyz:{
        xyz();
        }@

        Punit Tak

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Globinette
          wrote on last edited by
          #4

          Hello,

          To avoid the signal boilerplate, you can use "QJSValue":http://qt-project.org/doc/qt-5.1/qtqml/qjsvalue.html

          Please refer to "this post":http://qt-project.org/forums/viewthread/4521 for an example

          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