Solved QML and QAbstractTableModel
-
I have a subclassed a QAbstractTableModel, and I want to show the data in QML in various ways. Please see a small example here: https://github.com/olejl77/demomodel
It seems to be working, but change in values are not reflected in the QML. Also how can I show a single value from the model in QML?
-
@olejl77 I see that you update the values in
Row
objects but these changes needs to be notified to the view. This can be done using dataChanged signal. So once aRow
s value is updated you can for eg. emit a signal from thatRow
object and this signal can be connected to a slot in the model. Later this slot will emitdataChanged
signal. This signal takes an index which you can create using exact row and column which is going to be updated. You can store the row number inRow
object itself whereas column can be hardcoded since they are only 2.Also how can I show a single value from the model in QML?
Create a
Q_INVOKABLE
function or a public slot inside the model which will return the single value from there. -
@p3c0: Thanks for the information. That solved the issue with the ListView and GridView not updating.
I also managed to retrieve a single value, however I didn't manage to "bind" that value in order for it to update when it changes. How can I do that?
(I have updated github) -
I also managed to retrieve a single value, however I didn't manage to "bind" that value in order for it to update when it changes. How can I do that?
Try this:
https://wiki.qt.io/How_to_Bind_a_QML_Property_to_a_C%2B%2B_FunctionAfter that when the value in your model changes just call
someFunction
(your function) which will then emit a signal which will notify the QML and update the text. -
Thanks, I have solved it now.