Hello,
is it possible to add a derived c++ QAbstractListModel model to a ListPage with delegated SimpleRow ?
I implemented such a class as singleton and registered it in the main.cpp file via qmlRegisterSingletonType(..).
In QML I set the ListPage model to the registered singleton model and delegate to SimpleRow. With this constellation
I receive a “ReferenceError: modelData is not defined” error. But when I change the SimpleRow with a Rectangle element,
my c++ model works.
Here is some Code:
main.cpp
...
qmlRegisterSingletonType<SetListModel>("NoNameApp", 1, 0, "SetListModel", SetListModel::getInstance);
...
ListPage.qml (with SimpleRow)
import QtQuick 2.4
import Felgo 3.0
import NoNameApp 1.0
ListPage {
id: _set_listpage
title: qsTr("Test")
emptyText.text: qsTr("No data available")
delegate: SimpleRow{
showDisclosure: false
image.radius: image.height
image.fillMode: Image.PreserveAspectCrop
autoSizeImage: true
imageMaxSize: dp(48)
detailTextItem.maximumLineCount: 2
detailTextItem.elide: Text.ElideRight
detailTextItem.text: model ? ""+model.birthdate + "\n" + ""+model.additionText : ""
imageSource: model ? model.imageSmall : ""
textItem.font.pixelSize: sp(16)
onSelected: {
navigationStack.popAllAndPush(_set_detail_page, {
setName: model.text,
addition: model.additionText,
imageurl: model.imageBig
})
}
}
Component {
id: _set_detail_page
SetDetailPage {}
}
model: SetListModel
}
ListPage.qml (with Rectangle)
import QtQuick 2.4
import Felgo 3.0
import NoNameApp 1.0
ListPage {
id: _set_listpage
title: qsTr("Test")
emptyText.text: qsTr("No data available")
delegate: Rectangle{
width: parent.width
height: 100
color: "red"
Text{
text: model.id+":"+model.text
}
}
Component {
id: _set_detail_page
SetDetailPage {}
}
model: SetListModel
}
Best regards
Sascha