Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Intermittent crash passing QVariantMap from QML to C++ worker thread

Intermittent crash passing QVariantMap from QML to C++ worker thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 259 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.
  • vikramgV Offline
    vikramgV Offline
    vikramg
    wrote on last edited by vikramg
    #1

    I am running into a sporadic crash on Qt 5.12 which appears to be the same as the problem described here: a JS object is passed as the argument of a signal declared in QML and connected to a C++ slot in a worker thread. The C++ slot accepts the argument as a QVariant and converts it into a QVariantMap via toMap():

    void MyObj::slotVM(QString source, QVariant ur, int)
    {
        QVariantMap urvm = ur.toMap();
    

    The program occasionally crashes in the toMap function (when it doesn't crash, everything works correctly, as intended). The fix described in the SO post is this:

    The variant you have there is internally a QJSValue. In order to convert that to a map, we have to call deep into the JavaScript engine, construct scopes, and interact with the JavaScript heap. If any other JavaScript is running at the same time in a different thread, you're in trouble.
    Just extract the QVariantMap in the main thread and pass that to your functor as parameter."

    But does this mean that JS objects can never be simply passed cross-thread from QML to C++? If so, that seems to be a serious caveat that has not been mentioned here: https://doc.qt.io/qt-5/qtqml-cppintegration-data.html#qvariantlist-and-qvariantmap-to-javascript-array-and-object

    Is the only solution to "relay" the signal to the worker thread via an intermediate slot-signal pair in C++ in the main thread? Is a QVariantMap argument guaranteed to work within C++ (i.e. passing from a C++ signal in the main thread to C++ slot in worker thread?)

    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