Unsolved QSyncable - Synchronize data between models
-
@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 -
@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
-
@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.
-
@levelxxl I mean from Javascript / QML.
-
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 -
@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.
-
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.