Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt如何为ListView分配Qlist作为模型?_Qt_Listview_Qml - Fatal编程技术网

Qt如何为ListView分配Qlist作为模型?

Qt如何为ListView分配Qlist作为模型?,qt,listview,qml,Qt,Listview,Qml,我从XML文件中读取值并将其存储在对象中,对象存储在Qlist中。现在我想现在,如何在qml中将Qlist分配给Listview HomeController.h: struct PortalMapItemInfo { QString pstrTitle; QString pstrItemId; QString pstrDescription; QString pstrCreated; }; class HomeController : public QObject { Q_OBJECT

我从XML文件中读取值并将其存储在对象中,对象存储在Qlist中。现在我想现在,如何在qml中将Qlist分配给Listview

HomeController.h:

struct PortalMapItemInfo {
QString pstrTitle;
QString pstrItemId;
QString pstrDescription;
QString pstrCreated;
};

class HomeController : public QObject
{

Q_OBJECT

public:

Q_INVOKABLE bool eveReadXML();

}
HomeController.CPP:

void HomeController::eveReadXML()
{

//Read the xml Value and load it the object of the class
PortalMapItemInfo obj;

obj.pstrTitle = strTitle;
obj.pstrItemId = strItemId;
obj.pstrDescription = strDescription;
obj.pstrCreated = strCreated;

QList<PortalMapItemInfo> datalist;

datalist << obj; //Values are properly binded.

}

在qml文件中为列表设置一个对象名,然后根据其对象名查找列表,并设置其
model
属性。这是相当清楚的
ListView {
id: idListView
anchors {
left: parent.left
leftMargin: 10 * scaleFactor
right: parent.right
rightMargin: 10 * scaleFactor
top: rectangleToolBar.bottom
topMargin: 10 * scaleFactor
bottom: rectangleStatusBar.top
bottomMargin: 10 * scaleFactor
}

// model:???????????????????????????
delegate: comsearchDelegate
spacing: 10 * scaleFactor
clip: true

}
Component {
id: comsearchDelegate

Row {
spacing: 10 * scaleFactor

Image {
id: imageItem
width: 100 * scaleFactor
height: 70 * scaleFactor
source: thumbnailUrl
}

Column {
Layout.alignment: Qt.AlignTop
Text { text: title; font { pixelSize: 14 * scaleFactor; bold: true } }

}
}
}