[Merged] Accessing QML List Model element in C++
I have a custom component that can bind with a custom model that is derived from QAbstractItemModel, but what I am trying to do is to make the custom component to accept any kind of models including the standard QML ListModel element. I'm finding out that it's not easy to do this because the QML ListModel (or QDeclarativeListModel as it's defined internally) is in a private header. I'm struggling to find the best way to do this.
Can this be done? What's the best way to do this? If I have to use private headers, how can I use it?
I apologize in advance if you've seen this question posted in Qt Quick forum already, but after 2 weeks I still haven't received any feedback on this issue. I appreciate any help you can provide me because I'm stuck at this point.
I’m writing a QML plugin in Qt to return data from both MySql and Sqlite database. The feature that I’m trying to implement is the ability for the user in QML to modify data in the model and then write it back to the database. I have a SqlListModel that has an instance of QSqlTableModel. I have two classes, MySqlDatabase and SqliteDatabase, which are derived from a common database base class. When I try to use Sqlite database with my SqlListModel, it seems to be working. I can select, update, and remove existing data from the model and upon a submitAll call, all the changed data are written back to the database. It’s all fine and dandy until I try to use SqlListModel with MySqlDatabase. I can perform select and insert new records into the model and then it can write it back to the database. The issue is with updating/removing existing data in the database. I can’t seem to figure out why or a way to get around this issue.
Any tip is very appreciated.
hi ,can you tell me how do you select and insert new records into the model and write it back to the database ,can you give me some good idea, and can you show me your codes. thanks !