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. QSyncable - Synchronize data between models
Qt 6.11 is out! See what's new in the release blog

QSyncable - Synchronize data between models

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
16 Posts 5 Posters 9.3k 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.
  • V Vincent007

    Hi, @benlau

    Thanks for your contribution.

    I haven't tried QSyncable. I don't know whether my question is valid. You say "In QSyncable application, ListModel only keep a copy of the data." Does it mean the memory consumption of QSyncable is high? especially when the data size is big, for example, images or video clips are used as the data.

    benlauB Offline
    benlauB Offline
    benlau
    Qt Champions 2016
    wrote on last edited by
    #3

    @Vincent007 It should have no problem for regular data type like string , text , integer even you make a copy of data. Because you won't show too many information to user at a time.

    Image and video are another case. Usually you will only hold a reference to their position (e.g URL) and load via a cache manager / video manager. Holding in a list model is not suggested.

    However, QImage is in fact an implicitly sharing class. The memory consumption will be the same even you have multiple reference.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vincent007
      wrote on last edited by
      #4

      Hi @benlau ,

      Thanks for your reply.

      As I said earlier, why not share what you have done to Qt contributors? As especially, you have documented your work. Therefore they can understand what you have done quickly.

      benlauB 1 Reply Last reply
      0
      • V Vincent007

        Hi @benlau ,

        Thanks for your reply.

        As I said earlier, why not share what you have done to Qt contributors? As especially, you have documented your work. Therefore they can understand what you have done quickly.

        benlauB Offline
        benlauB Offline
        benlau
        Qt Champions 2016
        wrote on last edited by
        #5

        @Vincent007 No idea what to write in the email yet. So I pick another things to do first.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vincent007
          wrote on last edited by
          #6

          @benlau

          Why not include the content of README.md in the document of QSyncable generated by qDoc?

          benlauB 1 Reply Last reply
          0
          • V Vincent007

            @benlau

            Why not include the content of README.md in the document of QSyncable generated by qDoc?

            benlauB Offline
            benlauB Offline
            benlau
            Qt Champions 2016
            wrote on last edited by
            #7

            @Vincent007 Should be a good idea.

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #8

              Thanks for the component.
              Not a criticism as your library is built for a different type of programming but for readers landing on this page, if you can overcome "Implement your own QAbstactItemModel is troublesome." (maybe use QStandardItemModel using only QAbstactItemModel interface) a QIdentityProxyModel or QSortFilterProxyModel is probably what you are looking for

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              benlauB 1 Reply Last reply
              0
              • VRoninV VRonin

                Thanks for the component.
                Not a criticism as your library is built for a different type of programming but for readers landing on this page, if you can overcome "Implement your own QAbstactItemModel is troublesome." (maybe use QStandardItemModel using only QAbstactItemModel interface) a QIdentityProxyModel or QSortFilterProxyModel is probably what you are looking for

                benlauB Offline
                benlauB Offline
                benlau
                Qt Champions 2016
                wrote on last edited by
                #9

                @VRonin QStandardItemModel is easier to implement, but if user need to provide custom data, user still need to understand the concept of "Role" and reimplement QStandardItem. User need to aware that they can't update QStandardItem by just adding setXXXX function. They have to setup the "role" correctly.

                In this case, a variant list model approach (not a official component from Qt, but there has implementation available in few OSS projects) is much easier.

                So I don't think the statement is wrong.

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

                  Just by luck I found this: QtWS15- Lightning Talk, A new way for creating QML models from C++, Thomas Boutroue
                  https://www.youtube.com/watch?v=96XAaH97XYo

                  Tested it and found the QQmlObjectListModel to be the easiest way to use c++ models with QML. It is basically a QObject List wrapped in a QAbstractListModel. And every property you define in you QObject derived class becomes a role.

                  http://gitlab.unique-conception.org/qt-libraries/lib-qt-qml-tricks/blob/master/src/qqmlobjectlistmodel.h

                  If you use the QQMLHELPERS macros, you don't even need the bloated glue code in c++ to define properties.

                  http://gitlab.unique-conception.org/qt-libraries/lib-qt-qml-tricks/blob/master/src/qqmlhelpers.h

                  benlauB 1 Reply Last reply
                  0
                  • L levelxxl

                    Just by luck I found this: QtWS15- Lightning Talk, A new way for creating QML models from C++, Thomas Boutroue
                    https://www.youtube.com/watch?v=96XAaH97XYo

                    Tested it and found the QQmlObjectListModel to be the easiest way to use c++ models with QML. It is basically a QObject List wrapped in a QAbstractListModel. And every property you define in you QObject derived class becomes a role.

                    http://gitlab.unique-conception.org/qt-libraries/lib-qt-qml-tricks/blob/master/src/qqmlobjectlistmodel.h

                    If you use the QQMLHELPERS macros, you don't even need the bloated glue code in c++ to define properties.

                    http://gitlab.unique-conception.org/qt-libraries/lib-qt-qml-tricks/blob/master/src/qqmlhelpers.h

                    benlauB Offline
                    benlauB Offline
                    benlau
                    Qt Champions 2016
                    wrote on last edited by benlau
                    #11

                    @levelxxl In fact I would recommend his Variant List Model rather then a QObject list model.

                    src/qqmlvariantlistmodel.h · master · Qt Libraries / Qt QML Tricks · GitLab

                    Just consider the following scenario:

                    1. User would like to add a new item to list.

                    2. The app create a QObject then append to QObject list model (which is a global context property).

                    3. Then he go to another page. Several minutes later. The app crash suddenly.

                    Why? Because the QObject is created under JavascriptOwnership. It may be destroyed by GC. But C++ may not be aware of that. Ofcoz you could use a QPointer to hold the reference. But the data is already destroyed. QObject list model will lost the record.

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

                      You mean if a user adds a QObject from QML, or from c++? Till now I didn't run into a crash when I added QObjects from c++ only.

                      benlauB 1 Reply Last reply
                      0
                      • L levelxxl

                        You mean if a user adds a QObject from QML, or from c++? Till now I didn't run into a crash when I added QObjects from c++ only.

                        benlauB Offline
                        benlauB Offline
                        benlau
                        Qt Champions 2016
                        wrote on last edited by
                        #13

                        @levelxxl I mean from Javascript / QML.

                        1 Reply Last reply
                        1
                        • I Offline
                          I Offline
                          IPO_DEV
                          wrote on last edited by
                          #14

                          Hi benlau, can qsyncable handle tree structures as well ?
                          Does it produce a valid abstractitemmodel for trees ? Have you got an example ? What is your experience with this approach for larger datasets ? lets say about 1000 entries ?
                          thank you,
                          Michael

                          benlauB 1 Reply Last reply
                          0
                          • I IPO_DEV

                            Hi benlau, can qsyncable handle tree structures as well ?
                            Does it produce a valid abstractitemmodel for trees ? Have you got an example ? What is your experience with this approach for larger datasets ? lets say about 1000 entries ?
                            thank you,
                            Michael

                            benlauB Offline
                            benlauB Offline
                            benlau
                            Qt Champions 2016
                            wrote on last edited by
                            #15

                            @IPO_DEV QSyncable could be used for nested list model. But it do not fit with tree view yet. I have tried with few hundred of items which is still smooth.

                            1 Reply Last reply
                            1
                            • benlauB Offline
                              benlauB Offline
                              benlau
                              Qt Champions 2016
                              wrote on last edited by
                              #16

                              Hello,

                              I am going to write a new FastDiffRunner component to replace the original diff runner for better performance. And here is the proposed API. If anyone is interested, please feel free to comment and making suggestion.

                              [RFC] FastDiffRunner · benlau/qsyncable

                              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