Async API in qml and storing QJSValue in C++ objects



  • I want to add async API in my qml application.
    I implemented it in c++:

    Q_INVOKABLE void getObject(QJSValue value);
    

    and use it from qml this way:

    myAPi.getObject(
        function()  {
           alert("hi")  
        }
    );
    

    Is it safe to store QJSValue ( that is a handle to JavaScript function) in C++ and call its later? Can garbage collector remove this function and calling it later may cause runtime error?


  • Moderators

    Hi,

    @Rem-Kolomna said:

    Is it safe to store QJSValue ( that is a handle to JavaScript function) in C++ and call its later? Can garbage collector remove this function and calling it later may cause runtime error?

    Yes, it's safe. QJSValue is not just a handle. You will have a full a copy of the function in C++, so it will remain even if the original is removed.



  • ok, thank you!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.