PDA

View Full Version : How to save data in a three structure without use of QTreeWidget or other GUI classes



gQt
18th March 2011, 12:29
Hi all,

My program parses an xml file. I want to save the data in a three structure. The program has to run from crontab so it can not use GUI-classes like QTreeWidget combined with QTreeWidgetItem. How can I save the data in a Three structure without using QtreeWidget? Is it possible to use QTreeWidgetItem with no QTreeWidget or should I look in to other QT classes?
I am using Qt4 on Ubuntu Lucid 10.04

Any help is deaply appreciated!
gQt

agarny
18th March 2011, 13:03
QTreeWidget shouldn't be used in the first place. I don't know which version of Qt you are using exactly, but if possible you should use QTreeView and then set a data model to it.

gQt
22nd March 2011, 10:45
Thanks agarny!
I can not use any classes with graphics so the solution as I understands it is to use QTreeWidgetItem or QStandardItemModel to create a tree structure.
http://doc.qt.nokia.com/4.5/qstandarditemmodel.html#item

But how do you traverse the tree structure if you can not place the model in to a QTreeView or
the QTreeWidgetItem into a QTreeWidget?

agarny
22nd March 2011, 10:58
But how do you traverse the tree structure if you can not place the model in to a QTreeView or the QTreeWidgetItem into a QTreeWidget?You might want to read up on QStandardItemModel and the like. The whole idea of that class is to offer a means of managing your data. QTreeView and the like are just ways of presenting your data to your users.

Anyway, personally, I use QStandardItemModel and I load/save the data it contains by recursively 'walking through' its structure, starting from QStandardItemModel::invisibleRootItem() which returns a QStandardItem object.

gQt
22nd March 2011, 17:24
Hi,

I think I will use QTreeWidgetItem - found out that the tree can be traversed with the childCount() , child(int) and parent() functions. So I guess that solves the problem for now. Thanks for your suggestions.