Populating TreeView data from external QSettings file
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:
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:
| |---sun01, sun01vol=45
| |--- sun02, sun02vol=24
| |---mon02, mon02vol=75
| |---sun03, sun03vol=50
| |---mon01, mon01vol=40
so far I had no luck in my tries...I'd really appreciate help..
please help anyone?...
Not sure a t all, but I feel you need some basic programming notations. Do you know how to create a basic C++ tree structure?
You should understand that before trying to use Qt's structures.
Could you please refer me to a proper guide of C++ tree structure?
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.html
or 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 ...
Thanks, but, where can I get reference about getting data to a tree view from an external source rather than internal one?
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...
Could you please be more specific? What do you mean with internal / external sources?
Internal- meaning the data comes from inside the program.
External - the data comes from a file - in my case a configuration file (.ini)
The main difference is that the data ain't defined within the program but comes from an external source.