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. Async API in qml and storing QJSValue in C++ objects
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.1k Views 2 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.
  • R Offline
    R Offline
    Rem-Kolomna
    wrote on last edited by Rem-Kolomna
    #1

    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?

    JKSHJ 1 Reply Last reply
    0
    • R Rem-Kolomna

      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?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      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.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      1
      • R Offline
        R Offline
        Rem-Kolomna
        wrote on last edited by
        #3

        ok, thank you!

        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