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 pass QML function from QML to C++ and than back to QML ?
Forum Updated to NodeBB v4.3 + New Features

How do I pass QML function from QML to C++ and than back to QML ?

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.3k 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.
  • A Offline
    A Offline
    aabc
    wrote on 14 Jan 2014, 07:28 last edited by
    #1

    How do I pass QML function from QML to C++ and than back to QML ?

    1 Reply Last reply
    0
    • U Offline
      U Offline
      unai_i
      wrote on 14 Jan 2014, 09:42 last edited by
      #2

      Hi,
      I'm not sure whet exactly you mean by passing function from QML to C++ or the other way but I will try to give you some hints.
      You can call C++ slots, or functions preceded by Q_INVOKABLE from QML. Parameters can be javascript variables or properties from QML/C++, you get a result (if return not void) as javascript variable.
      You may be able to call QML/javascript function using a QQmlExpression instance on the right context. You get the result as a QVariant. (I haven't tested this solution yet)
      Hope it helps.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aabc
        wrote on 14 Jan 2014, 09:46 last edited by
        #3

        Thanks unai_i,

        How do I call the function using QQmlExpression ?

        1 Reply Last reply
        0
        • U Offline
          U Offline
          unai_i
          wrote on 14 Jan 2014, 13:34 last edited by
          #4

          Hi,
          You can have a look at "QQmlExpression documentation page":https://qt-project.org/doc/qt-5/qqmlexpression.html. There is a little code snippet which loads a qml file and evaluates an expression in the context of that qml file. You can then change "width * 2" example expression to your desired expression or function call and change the context to suit your needs.
          If the doc page is not enough, can you specify which part you don't understand?

          1 Reply Last reply
          0

          1/4

          14 Jan 2014, 07:28

          • 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