Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    QML and Qt Quick
    2
    4
    1025
    Loading More Posts
    • 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
      aabc last edited by

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

      1 Reply Last reply Reply Quote 0
      • U
        unai_i last edited by

        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 Reply Quote 0
        • A
          aabc last edited by

          Thanks unai_i,

          How do I call the function using QQmlExpression ?

          1 Reply Last reply Reply Quote 0
          • U
            unai_i last edited by

            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 Reply Quote 0
            • First post
              Last post