How to access C++ Model data directly from QML without any ListView/Repeater/etc ?
-
Hello everyone!
I am a beginner in Qt and QML. So far I am able to easily access my C++ Models (subclasses of QAbstractListModel) easily from QML via Controls like ListView, Repeater, ComboBox, etc.
However, I have reached a point where I would like to access data of my model via JavaScript in a QML function. Let's say, I would want to call thedatamethod of my model directly from QML, and pass in the row information. How do i do that?Currently, I am having a
Q_INVOKABLEmethod in my C++ code which accepts row number, and returns the appropriate value by invokingdatawithin it.Is there a proper way to do this other than this? Initially I used
QListinstead of models, after reading up on QML Performance Optimisation guide, it looks like that is very performance heavy since it involves copying all at once when dealing with larger custom classes.Thank you, please excuse and correct if I said anything wrong.
-
What you are doing(Q_INVOKABLE) is the only way to access the model data
-
Hello everyone!
I am a beginner in Qt and QML. So far I am able to easily access my C++ Models (subclasses of QAbstractListModel) easily from QML via Controls like ListView, Repeater, ComboBox, etc.
However, I have reached a point where I would like to access data of my model via JavaScript in a QML function. Let's say, I would want to call thedatamethod of my model directly from QML, and pass in the row information. How do i do that?Currently, I am having a
Q_INVOKABLEmethod in my C++ code which accepts row number, and returns the appropriate value by invokingdatawithin it.Is there a proper way to do this other than this? Initially I used
QListinstead of models, after reading up on QML Performance Optimisation guide, it looks like that is very performance heavy since it involves copying all at once when dealing with larger custom classes.Thank you, please excuse and correct if I said anything wrong.
QAbstactItemModel::datais already Q_INVOKABLE. -
What you are doing(Q_INVOKABLE) is the only way to access the model data
-
R rnayabed has marked this topic as solved on