Generate an XML file using the QML Listmodel
-
Hi All,
I would like to generate a xml file (either in SAX or DOM format whichever is convenient) using a Qt C++ class and the data for the creation of this xml file need to fetched from the QtQuick List model(data model).
When the data has been extracted from the data model it will need to be written to a file.
Please suggest possible solutions for the same.BR,
Aster -
Hi @Ravikiran-V-N,
The are several ways access aListModel
from C++. In each case you will need to get access toListModel
object which can be done by usingfindChild
provided you have setobjectName
to theListModel
. Once that is done,-
Access
ListModel
functions . The function of interest here would be get. You can follow this document to understand how to invoke QML functions from C++. -
ListModel
is anQAbstractItemModel
so once you get access ofListModel
on C++ side, cast it toQAbstractItemModel
and use it functions for eg. data() to access theListModel
data.
Later use QXmlStreamWriter to create XML file. There's QtXml module too but it is not supported anymore.
Hope this gets you going :)
Btw. can you explain why you are preferring populating
ListModel
instead of C++ models directly ? As anyway at the end you are coming to C++ for further processing. -