1 year ago
#358201
Petr Pivonka
Qt Data Models vs QML Data Models
Generally, there are two distinctive ways how to define, create and attach the data model in the C++/Qt/QML model/delegate/view architecture. Let's illustrate them on a table view example:
#1. Inherite own C++/Qt class from QAbstractItemModel (or from its specialized children QAbstractTableModel for our example), define own C++/Qt/SQL/XML/JSON/etc data source/storage and re/write the necessary Qt model virtual methods to secure the upward/downward data flow. Then just initialize the model property of QML TableView when QML engine starts.
or
#2. Define own QML model using QML TableModel/TableModelColumn, fill the QML TableModel rows property with some static data or append/insert/remove some dynamic data using the QML TableModel's data manipulation methods. Then just refer such a QML TableModel from QML TableView.
And my questions are as follows:
Q1: Can I call the Qt QAbstractTableModel's data(index, role) and setData(index, value, role) methods and QML TableModel's data(index, role) and setData(index, value, role) methods from my QML JavaScript code the same way for both model definition options as described above? Hint: my impressions after extensive tests are that data()/setData() in QML JavaScript works just with QML TableModel, not for Qt QAbstractTableModel ...
Q2: If the answer for Q1 was YES (I pray-), how the C++/Qt QVariant is to be cast/converted/treated on the QML JavaScript side? The Qt QAbstractItemModel data()/setData() interchange all data as QVariants ...
Thank you for your expertize, this is described very confusing way in the Qt/QML documentation or, better said, not described at all ...
qt
view
model
delegates
qml
0 Answers
Your Answer