Access lists from qml in c++
Solved
General and Desktop
-
I have a list which are in a qml widget and the widget is called in the mainwindow.
Mainwindow snippet:QQuickWidget *widget = new QQuickWidget; widget->setSource(QUrl(QStringLiteral("qrc:/qml_maps/Viewer.qml")));
The lists can be accessed in Viewer.qml. How do I access it in a different c++ class.
Thanks!!
-
I have a list which are in a qml widget and the widget is called in the mainwindow.
Mainwindow snippet:QQuickWidget *widget = new QQuickWidget; widget->setSource(QUrl(QStringLiteral("qrc:/qml_maps/Viewer.qml")));
The lists can be accessed in Viewer.qml. How do I access it in a different c++ class.
Thanks!!
-
@saitej Use findChild to access the object containing the list by object name. Then cast it to QList
-
@p3c0
Ya I had tried this way already. I m not sure of the syntaxQQuickWidget *widget = new QQuickWidget; widget->setSource(QUrl(QStringLiteral("qrc:/qml_maps/Viewer.qml"))); QList l1; l1 = widget->findChild<QList *>("MarkerList");
-
@saitej
What isMarkerList
? By list do you meanListView
?
If that's the case then you will need to cast it toQQuickItem
. -
@p3c0
No. Its an array (property of the viewer)Viewer.qml
Rectangle{ id: rect property var MarkerList: [] ....................... }