Hi EveryOne,
I have a C++ class that does some operations
The method : getDataFromServer() exports some Data from server, it works well
for (int i = 0; i < projects.size(); ++i)
{
qDebug() << "result : " << projects[i];
}
for (int i = 0; i < projects.size(); ++i)
{
qDebug() << "result : " << projects[i];
}
To copy to clipboard, switch view to plain text mode
I want to display data in Listview QML
QML code
Rectangle
{
Component.onCompleted: {
ClassTest.getDataFromServer();
}
ClassTest{
id: classTest
}
Item {
width: 800
height: 600
ListView {
id: listView
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
width: 0.25 * parent.width
focus: true
model: myModel
delegate: Item {
width: parent.width
height: 22
Text {
anchors.centerIn: parent
text: "data"
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log(model.index)
}
}
}
}
}
Rectangle
{
Component.onCompleted: {
ClassTest.getDataFromServer();
}
ClassTest{
id: classTest
}
Item {
width: 800
height: 600
ListView {
id: listView
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
width: 0.25 * parent.width
focus: true
model: myModel
delegate: Item {
width: parent.width
height: 22
Text {
anchors.centerIn: parent
text: "data"
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log(model.index)
}
}
}
}
}
To copy to clipboard, switch view to plain text mode
getDataFromServer() code
...
// getData OK
for (int i = 0; i < projects.size(); ++i)
{
qDebug() << "result : " << projects[i];
}
QQuickView *view= new QQuickView;
QQmlContext *c = view->engine()->rootContext();
c
->setContextProperty
("myModel",
QVariant::fromValue(projects
));
...
// getData OK
for (int i = 0; i < projects.size(); ++i)
{
qDebug() << "result : " << projects[i];
}
QQuickView *view= new QQuickView;
QQmlContext *c = view->engine()->rootContext();
c->setContextProperty("myModel", QVariant::fromValue(projects));
To copy to clipboard, switch view to plain text mode
Any help plz
Cheers,
Bookmarks