Register C++ class derived from QAbstractListModel
-
I am following the examples here: https://www.qt.io/product/qt6/qml-book/ch17-qtcpp-cpp-models#a-simple-model.
MyClass.h
class MyClass : public QAbstractListModel { ...
But I cannot register the class:
error: static assertion failed: It is not possible to register an abstract type with qmlRegisterType. Maybe you wanted qmlRegisterUncreatableType or qmlRegisterInterface?
It works if I derive from QObject, I can compile the code and use the class in main.qml.
I also tried to use QML_ELEMENT.The class is used for a ListView, as the example so I am supposed to use a QAbstractListModel right?
Why can't I use it?
-
I am following the examples here: https://www.qt.io/product/qt6/qml-book/ch17-qtcpp-cpp-models#a-simple-model.
MyClass.h
class MyClass : public QAbstractListModel { ...
But I cannot register the class:
error: static assertion failed: It is not possible to register an abstract type with qmlRegisterType. Maybe you wanted qmlRegisterUncreatableType or qmlRegisterInterface?
It works if I derive from QObject, I can compile the code and use the class in main.qml.
I also tried to use QML_ELEMENT.The class is used for a ListView, as the example so I am supposed to use a QAbstractListModel right?
Why can't I use it?
@realroot said in Register C++ class derived from QAbstractListModel:
Why can't I use it?
Impossible to say for sure without seeing more code.
My guesses:
- you forgot about Q_OBJECT macro
- you did not reimplement abstract methods from
QAbstractListModel
(this is precisely what this error tells you)
As the documentation say:
When subclassing QAbstractListModel, you must provide implementations of the rowCount() and data() functions
-
@realroot said in Register C++ class derived from QAbstractListModel:
Why can't I use it?
Impossible to say for sure without seeing more code.
My guesses:
- you forgot about Q_OBJECT macro
- you did not reimplement abstract methods from
QAbstractListModel
(this is precisely what this error tells you)
As the documentation say:
When subclassing QAbstractListModel, you must provide implementations of the rowCount() and data() functions
The error message is not so clear.
I did not make the implementations of the rowCount() and data() functions, thanks.
I am replacing the configuration file that it is a QML file.
I am not sure about the implementation.I have a ListView whose elements are ListView.
ListView
s have a few properties and the inner one hasListElement
s:import QtQuick Item { id: config //Inner ListView Item { id: w001 property bool defAutomatic: true property int sets: 1 property string woName: "30 seconds" property bool initPrep: true property int exTotal: w001timers.count property alias timers: w001timers property int setTotal: w001timers.setTotal property int woTotal: w001timers.woTotal ListModel { id: w001timers property int sets: w001.sets property string woName: w001.woName property bool initPrep: w001.initPrep property int setTotal: { for (var i = 0; i < count; i++) { setTotal += get(i).countdownValue; } } property int woTotal: setTotal * sets ListElement { automatic: true countdownValue: 30 timerName: "go" prepare: false } } } ...
I am adding a C++ back end to save/load/edit the configuration, using only QML works but that looks like suitable for C++.
I thinking about saving it as json.Any suggestion? I am a beginner.
Should I submit a new topic? -
-
-