Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Populating TreeView data from external QSettings file

Populating TreeView data from external QSettings file

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shayb
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      shayb
      wrote on last edited by
      #2

      please help anyone?...

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Skyrpex
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          shayb
          wrote on last edited by
          #4

          Could you please refer me to a proper guide of C++ tree structure?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Skyrpex
            wrote on last edited by
            #5

            Just ask Google :-) Four example, you could start with binary trees

            1 Reply Last reply
            0
            • N Offline
              N Offline
              NicuPopescu
              wrote on last edited by
              #6

              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 ...

              Cheers!

              1 Reply Last reply
              0
              • S Offline
                S Offline
                shayb
                wrote on last edited by
                #7

                Thanks, but, where can I get reference about getting data to a tree view from an external source rather than internal one?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Skyrpex
                  wrote on last edited by
                  #8

                  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!

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    shayb
                    wrote on last edited by
                    #9

                    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...

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Skyrpex
                      wrote on last edited by
                      #10

                      Could you please be more specific? What do you mean with internal / external sources?

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        shayb
                        wrote on last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved