Populating TreeView data from external QSettings file
-
Hey,
I'm new to Qt programming, and managed to learn and write some code for Model/View programming in some level, but I'm struggling on finding help in this forum or on Qt's documentation about populating TreeView.
I've created a configuration file of an INI format, which is stored in a directory on my computer.
the file contain keys and values from this type of format:
sun01=rock
sun01vol=45
sun02=rock
sun02vol=24
sun03=pop
sun03vol=50
.
.
mon01=pop
mon01vol=40
mon02=rock
mon02vol=75
...etc
i.e I'm making playlist of genre and volumes for each day and hour of the week. My current goal is to take every genre and put as a parent and to insert the volume and the day/hour as a child
for instance, for the example above the TreeView should display:
@
[root]
|---rock
| |---sun01, sun01vol=45
| |--- sun02, sun02vol=24
| |---mon02, mon02vol=75
|---pop
| |---sun03, sun03vol=50
| |---mon01, mon01vol=40@
so far I had no luck in my tries...I'd really appreciate help..
thanks -
Just ask Google :-) Four example, you could start with binary trees
-
check the examples in qt doc:
"Simple Tree Model Example":qthelp://com.trolltech.qt.485/qdoc/itemviews-simpletreemodel.html
"Editable Tree Model Example":qthelp://com.trolltech.qt.485/qdoc/itemviews-editabletreemodel.htmlor in your case, I think using direct a QTreeWdiget having a predefined model would be enough ... I would suggest to play with someone in QtCreator, add few items,build the project and then check the ui header file to find out how should look your populating code ...
Cheers!
-
You can use "QSettings":http://qt-project.org/doc/qt-5.0/qtcore/qsettings.html to read the .ini file.
To create and display your tree, you could use "QTreeWidget":http://qt-project.org/doc/qt-5.0/qtwidgets/qtreewidget.html and "QTreeWidgetItem":http://qt-project.org/doc/qt-5.0/qtwidgets/qtreewidgetitem.html..
Alternatively, you could use "QStandardItemModel":http://qt-project.org/doc/qt-5.0/qtgui/qstandarditemmodel.html, "QStandardItem":http://qt-project.org/doc/qt-5.0/qtgui/qstandarditem.html and "QTreeView":http://qt-project.org/doc/qt-5.0/qtwidgets/qtreeview.html for that purpose.
Hope it helps!
-
Thanks for the reply.
I am able to read an INI file and write to in by functions I am already femiliar with , and creating views and modifying them BUT from internal sources, where I modify the data inside the program, however I am laking on knowledge with which functions I should use for my purposes...