Qt如何将Qlist指定为ListView的模型?

时间:2016-10-05 15:52:53

标签: qt listview qml

我从XML文件中读取值并将其存储在对象中,并将对象存储在Qlist中。这个对象在HomeController.cpp中编码。现在我想现在,如何在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.

}

ListPortalItem.Qml

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 } }

}
}
}

0 个答案:

没有答案