QML write back table entries to a list in C++
-
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 -
@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 -
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
andQAbstractTableModel
.
You could then modify the roles directly from the delegate and handle it insetData
. -
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.
@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