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. [Merged] Accessing QML List Model element in C++
Forum Updated to NodeBB v4.3 + New Features

[Merged] Accessing QML List Model element in C++

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 3.7k 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.
  • T Offline
    T Offline
    tuanster
    wrote on last edited by
    #1

    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?

    Thanks!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tuanster
      wrote on last edited by
      #2

      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.

      Thanks,

      TP

      1 Reply Last reply
      0
      • C Offline
        C Offline
        changli85
        wrote on last edited by
        #3

        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 !

        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