Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[solved] XML model?
I'd would like to create a server that provides data as XML and a client that shows this in a QTableView. The data is logged from a system, so it changes regularly.
My question is:
Can I somehow create model approach similar to an QSqlModel, so that I easily could display the data and keep it synced over a TCP connection? Thanks!
gmaro last edited by
I don't think there is a direct approach, the reason is since sql tables are well suited to display in table format "as is" and xml is rather suitable to display as a structured tree. Simple question is how to display "properly" the structure of items that have other child items and those items have also child items? Many ways to do that, but tree is more suitable.
It may be cofortable for you to use the QDomDocument or QXmlStreamReader.
Please look also ath the "Simple DOM Model Example":http://qt-project.org/doc/qt-4.8/itemviews-simpledommodel.html maybe you can use similar approach but change only the way of viewing the data.
Thank you! I do see your point, but what about creating a custom data model based on the XML format? Could this be done is such way, and if so, how hard is it?
gmaro last edited by
That depends what do you need to do with it.
If you want to create some new model based on the QAbstractItemModel class, you need to prepare for quite a lot of work i think.
Personally I don't think you need to do that.
If your xml is suitable to display in a table. Just use the QTableView and QStandardItemModel which is simple and ready to use.
I think some simple less-work approach will be just to:
set QStandardItemModel to QTableView,
when new xml comes in, parse it (using QDomDocument, QXmlStreamReader or even QXmlSimpleReader), and fill/replace the QStandardItemModel data. The data in the view will be automatically refreshed.
If you still want to subclass the QAbstractItemModel, i thinkt the Simple DOM Model Example shows this really good, and as you see, you'll have a lot of coding in that case.
Ok, Thank you, that's what I wanted to know.