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. QML write back table entries to a list in C++
Forum Updated to NodeBB v4.3 + New Features

QML write back table entries to a list in C++

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 456 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.
  • msauer751M Offline
    msauer751M Offline
    msauer751
    wrote on last edited by
    #1

    Hi,

    in my application I use a QQmlListProperty Q_PROPERTY element to print a table in my QML view with delegate function. How can I change these entries and write back in my database (C++ class)?

    Or what is the correct to do to display the content of a database table where I can add new entries or change existing entries?

    Thank you for your help.

    BR
    martin

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @msauer751 said in QML write back table entries to a list in C++:

      QQmlListProperty

      this example may help you.
      https://doc.qt.io/qt-6/qtqml-referenceexamples-properties-example.html

      1 Reply Last reply
      0
      • GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        QQmlListProperty is not the proper solution to expose C++ data to QML. It is made to be populated declaratively from QML.

        Use a proper model inheriting from QAbstractListModel and QAbstractTableModel.
        You could then modify the roles directly from the delegate and handle it in setData.

        1 Reply Last reply
        0
        • msauer751M Offline
          msauer751M Offline
          msauer751
          wrote on last edited by
          #4

          @JoeCFD

          What do you mean with role? I am looking for QAbstractListModel in the net and I can find a lot of pages. They are using an enumeration with Qt:BaseRole but I don't understand what this is.

          JoeCFDJ 1 Reply Last reply
          0
          • msauer751M msauer751

            @JoeCFD

            What do you mean with role? I am looking for QAbstractListModel in the net and I can find a lot of pages. They are using an enumeration with Qt:BaseRole but I don't understand what this is.

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #5

            @msauer751 if you have only one column, QStringListModel is a better choice.
            https://stackoverflow.com/questions/18641530/what-are-roles-in-qt-model-and-what-does-setrolenames-do
            https://stackoverflow.com/questions/18616497/how-to-use-models-with-qml/18622443#18622443

            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