QSyncable - Synchronize data between models
-
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.
@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.
-
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.
-
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.
@Vincent007 No idea what to write in the email yet. So I pick another things to do first.
-
@Vincent007 Should be a good idea.
-
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 -
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@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.
-
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=96XAaH97XYoTested 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.
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
-
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=96XAaH97XYoTested 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.
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
@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:
-
User would like to add a new item to list.
-
The app create a QObject then append to QObject list model (which is a global context property).
-
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.
-
-
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.
-
-
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 -
Hello,
I am going to write a new
FastDiffRunnercomponent 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.