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. [SOLVED] Qt 5.2 c++ model update stops working after a while
QtWS25 Last Chance

[SOLVED] Qt 5.2 c++ model update stops working after a while

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 1.8k Views
  • 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.
  • L Offline
    L Offline
    levelxxl
    wrote on last edited by
    #1

    Hi everyone,

    I have an App, that works under Qt 5.1 (Windows), where I update a c++ model quite often, and show the result in two nested ListViews. But under Qt 5.2, after a few seconds the ListViews stop showing the changes of the model. When I slow down the update rate, it works longer, but after a while also stops working. I can't see any errors or warnings.

    Has something changed in Qt 5.2, that I should be aware of, or can this be a bug?

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you write a minimal application that reproduces this ? If so, it might be a bug/regression. You should have a look at the "bug report system":http://bugreports.qt-project.org to see whether it's something known. If not you should consider opening a new report providing that minimal compilable example

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        levelxxl
        wrote on last edited by
        #3

        It looks like the problem is related to the GC of the Javascript site. I pass the model to the second ListView via

        @Q_INVOKABLE JobEntryModel *getModelFor(int index);@

        and added a QDebug to the destructor of the model. After a few seconds the destructor gets called. I don't know why this works in Qt 5.1. From what I see it shoudn't work in any version.

        What is the right way to dynamically pass a model from c++ to a ListView?

        Thanks

        1 Reply Last reply
        0
        • L Offline
          L Offline
          levelxxl
          wrote on last edited by
          #4

          I have found a solution. When I set
          @QQmlEngine::setObjectOwnership(model, QQmlEngine::CppOwnership);@
          in
          @Q_INVOKABLE JobEntryModel *getModelFor(int index);@

          QML doesen't get the ownership and the GC will not destroy the model.

          Thanks

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            It's still curious that the behavior changed like that. You should ask about that on the interest mailing list. You'll find Qt's developers/maintainers there (this forum is more user oriented)

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • C Offline
              C Offline
              chrisadams
              wrote on last edited by
              #6

              It didn't change. The ownership semantics of QObject* values returned from Q_INVOKABLE functions has always been JavaScriptOwnership by default unless the user manually sets CppOwnership on it.

              The issue here is that v8's garbage collector doesn't run until it hits a "high watermark" level for memory usage, which means that in many applications on desktop, it never gets run. With 5.2 and v4vm, it could be that memory management is more deterministic, resulting in shorter and more regular collection cycles. This would lead to the behaviour seen above.

              Cheers,
              Chris.

              1 Reply Last reply
              0
              • L Offline
                L Offline
                levelxxl
                wrote on last edited by
                #7

                Thank you for the explanation.

                I like the new behavior of the GC, because it shows me that I have a problem in my code. So I can find it and fix it.

                Coming form only c++, I must say that the JavaScriptOwnership issue surprised me. For me it is odd, that someone else is deleting objects I created in c++.

                Thanks again.

                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