Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-138454

Add a warning that QIfPendingReply doesn't apply Javascript ownership to its contained value

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • Qt Interface Framework
    • None

    Description

      I had a Q_INVOKABLE method returning a QObject-derived class from C++ to QML. By default, such methods apply QQmlEngine::JavaScriptOwnership to the object. (https://doc.qt.io/qt-6/qtqml-cppintegration-data.html#data-ownership)

      I later decided to refactor the method to return a QIfPendingReply instead to make the method async. I created the object on a separate thread and used setSuccess to assign it to the reply. What I didn't realize was that I would have to manually set JavaScript Ownership on the object to avoid memory leaks.

      While this may seem obvious, I believe it might cause some headaches that could be avoided with a warning in the docs.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            gagi Dominik Holland
            bobini Tomasz Kalisiak
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes