Unsolved How to access QVariantList in Qml listview
-
Hi i am new Qt , any one help me how to access QVariantList in Qml listview
I tried follwing code
c++ class:
{
QJsonObject m_DataSourceObject = JsonDocument.object();
QJsonArray m_DataSourceArray = m_DataSourceObject.value(QString("camera")).toArray();QVariantMap mainmap = m_DataSourceObject.toVariantMap(); QVariantList phraseList = mainmap["camera"].toList();
setTesting(phraseList);
}
QVariantList Jsonparsing::testing(void)
{
return mTesting;
}
void Jsonparsing::setTesting(QVariantList value)
{
mTesting = value;
emit testingChanged(value);
}Qml:
property var test: jsonparsing.testing
ListModel {
id: model
Component.onCompleted: {
for(var i=0; i<5; i++){
append({"name": test[1]});
}
}
}ListView { id: list anchors.fill: parent model: model anchors.top: parent.top interactive: false delegate: Component { ColumnLayout { anchors.fill: parent TextEdit { width: 93 height: 25 text: name color: "red" font.pixelSize: 22 anchors.left: parent.left anchors.leftMargin: 32 } } } }
-
@Raji hi,
i guess you have a Q_PROPERTY for your QVariantList mTesting , it must be directly accessibleListView { id: list anchors.fill: parent model: jsonparsing.testing
@Raji said in How to access QVariantList in Qml listview:
delegate: Component {
ColumnLayout {
anchors.fill: parent
TextEdit {
width: 93
height: 25
text: name
color: "red"
font.pixelSize: 22
anchors.left: parent.left
anchors.leftMargin: 32Don't use anchors in an item inside a Layout, you should have a warning in "Application output" tab saying that