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. Is it ok to pass a QJsonArray to qml?
Forum Updated to NodeBB v4.3 + New Features

Is it ok to pass a QJsonArray to qml?

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 2.1k 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.
  • W Offline
    W Offline
    wuarmin
    wrote on last edited by
    #1

    Hello,

    I love qml and think it's great.

    Recently I implemented a autocomplete suggestion-List and it worked like a charm.

    The use case was the following:

    A user can edit a text-field, embedded in the suggestionList-Component, and after some key-strokes suggestionList emits a signal, which should be handled by a parent. The handling parent calls the corresponding method of the api-Object(context-property). The api-object lives on c++ side and sends and receives the http-requests. After receiving the result-payload, the payload is deserialized and passed to qml via a signal emitted by the api-object. I passed the result in a QJsonArray and want to know, what you think about it? I'm asking, because I didn't find concrete documentation. Lots of people recommend a QAbstractListModel or a QQmlPropertyList, but I think that would be an overkill for my case.

    Furthermore I don't know, how I should use a QAbstractListModel in that case.

    Maybe you can help me.

    Thanks

    raven-worxR 1 Reply Last reply
    0
    • W wuarmin

      Hello,

      I love qml and think it's great.

      Recently I implemented a autocomplete suggestion-List and it worked like a charm.

      The use case was the following:

      A user can edit a text-field, embedded in the suggestionList-Component, and after some key-strokes suggestionList emits a signal, which should be handled by a parent. The handling parent calls the corresponding method of the api-Object(context-property). The api-object lives on c++ side and sends and receives the http-requests. After receiving the result-payload, the payload is deserialized and passed to qml via a signal emitted by the api-object. I passed the result in a QJsonArray and want to know, what you think about it? I'm asking, because I didn't find concrete documentation. Lots of people recommend a QAbstractListModel or a QQmlPropertyList, but I think that would be an overkill for my case.

      Furthermore I don't know, how I should use a QAbstractListModel in that case.

      Maybe you can help me.

      Thanks

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @wuarmin said in Is it ok to pass a QJsonArray to qml?:

      Furthermore I don't know, how I should use a QAbstractListModel in that case.

      1. implement custom C++ model for QML
      2. request data
      3. on data receive call model reset

      I passed the result in a QJsonArray and want to know, what you think about it?

      you should use QVariantList for JavaScript lists, as described in this section.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • W Offline
        W Offline
        wuarmin
        wrote on last edited by wuarmin
        #3

        Thank you for your response!
        So one can say passing a QVariantList improves the performance, cause no transformation has to be done?

        Yesterday I tried a different thing. I passed a QList containing QObject-derived heap-object-pointer. It worked, but I could not figure out, how I have to delete them correctly on qml side. I don't want to manage such memory things at c++ side, cause I'm just passing the QList. Qml should manage it. Can you put me in the right direction?
        Thanks and best regards.

        raven-worxR 1 Reply Last reply
        0
        • W wuarmin

          Thank you for your response!
          So one can say passing a QVariantList improves the performance, cause no transformation has to be done?

          Yesterday I tried a different thing. I passed a QList containing QObject-derived heap-object-pointer. It worked, but I could not figure out, how I have to delete them correctly on qml side. I don't want to manage such memory things at c++ side, cause I'm just passing the QList. Qml should manage it. Can you put me in the right direction?
          Thanks and best regards.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @wuarmin
          try using QQmlEngine::setObjectOwnership(object, QQmlEngine::JavaScriptOwnership) to let the JavaScript garbage collector take care of it.
          Basically objects created in QML have JavaScriptOwnership, objects created in C++ have CppOwnership.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved