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. Good way to make a standard tree model to develop both CLI and GUI application
Forum Update on Monday, May 27th 2025

Good way to make a standard tree model to develop both CLI and GUI application

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 3 Posters 1.3k 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.
  • K Offline
    K Offline
    Kien Bui
    wrote on last edited by
    #1

    I used QStandardModelItemModel for treeview show in GUI.
    But I can't using QStandardModelItemModel for develop CLI app.
    I want to create subclass of QAbstractItemModel for both TreeView and Model of CLI app.
    I saw [URL="http://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-treemodel-cpp.html"]simple tree model[/URL], but It is still difficult to modify for tree model, example: edit model, set, get property of item,....
    Where or How to help me make [B]StandardTreeModel [/B] which I can use to devboth GUI app and CLI app

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Your intention is to use model for both GUI and CLI. For CLI you need to call the appropriate functions of model on your own.

      Do you want to just display the model data in CLI ?
      Do you want to update the model data from CLI ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      K 1 Reply Last reply
      1
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        This would require a custom QAbstractProxyModel subclass to provide the interface the .Net component expects. interesting project but certainly not trivial.

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        0
        • dheerendraD dheerendra

          Your intention is to use model for both GUI and CLI. For CLI you need to call the appropriate functions of model on your own.

          Do you want to just display the model data in CLI ?
          Do you want to update the model data from CLI ?

          K Offline
          K Offline
          Kien Bui
          wrote on last edited by
          #4

          @dheerendra Sure.
          With the sample of Qt document, I can't use for my CLI app

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            How does the model works ? Just look at some example on QAbstractListModel in examples directory. There examples of how to write our own model. That should give you good idea on how to deal with model to fetch the data. At the minimum you need to worry about fetching the data on your from model for CLI app. You can write you tree data structure which is shared between the model and CLI app. In case of GUI view model acts like wrapper for Tree Datastructure. For cli it is direct interface you can define. Any change in data is reflected in both CLI and UI.

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            K 1 Reply Last reply
            0
            • K Offline
              K Offline
              Kien Bui
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • dheerendraD dheerendra

                How does the model works ? Just look at some example on QAbstractListModel in examples directory. There examples of how to write our own model. That should give you good idea on how to deal with model to fetch the data. At the minimum you need to worry about fetching the data on your from model for CLI app. You can write you tree data structure which is shared between the model and CLI app. In case of GUI view model acts like wrapper for Tree Datastructure. For cli it is direct interface you can define. Any change in data is reflected in both CLI and UI.

                K Offline
                K Offline
                Kien Bui
                wrote on last edited by
                #7

                @dheerendra
                It is folder and file tree, but I read this tree from API
                It includes of File/Folder name; Size.
                With this tree model, I can access the item, insert, set/get data item,...

                1 Reply Last reply
                0
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by
                  #8

                  Are you using QFileSystemModel for the same ?

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  K 1 Reply Last reply
                  0
                  • dheerendraD dheerendra

                    Are you using QFileSystemModel for the same ?

                    K Offline
                    K Offline
                    Kien Bui
                    wrote on last edited by
                    #9

                    @dheerendra
                    But QFileSystemModel is a GUI class.
                    Plus, How to import from json API to QFileSystemModel

                    1 Reply Last reply
                    0
                    • dheerendraD Offline
                      dheerendraD Offline
                      dheerendra
                      Qt Champions 2022
                      wrote on last edited by dheerendra
                      #10

                      Ok. If you are importing the data from JSON, QFileSystemModel is not right choice. You better stay with QStandardItemModel. I'm not sure about the data size.

                      Another suggestion If you have huge data size, you better write your own model and represent the data inside. Also you can keep the data also inside the model as JSON only. In your customised model, you can write data(...) function returning the data appropriately.

                      Additional information QStandardItemModel and QFileSystemModel are not UI classes. They are packaged inside GUI and Widgets modules respectively.

                      Dheerendra
                      @Community Service
                      Certified Qt Specialist
                      http://www.pthinks.com

                      K 1 Reply Last reply
                      0
                      • dheerendraD dheerendra

                        Ok. If you are importing the data from JSON, QFileSystemModel is not right choice. You better stay with QStandardItemModel. I'm not sure about the data size.

                        Another suggestion If you have huge data size, you better write your own model and represent the data inside. Also you can keep the data also inside the model as JSON only. In your customised model, you can write data(...) function returning the data appropriately.

                        Additional information QStandardItemModel and QFileSystemModel are not UI classes. They are packaged inside GUI and Widgets modules respectively.

                        K Offline
                        K Offline
                        Kien Bui
                        wrote on last edited by
                        #11
                        Addition information QStandardItemModel and QFileSystemModel are not UI classes. They are packaged inside GUI and Widgets modules respectively.
                        

                        So It is OK if I use QStandardItemModel to write a CLI app.
                        And Before in .pro file:

                        QT   -= GUI
                        

                        Now I can set QT += GUI
                        But I am not sure that what problem or conflict when I set GUI for CLI app.

                        1 Reply Last reply
                        0
                        • dheerendraD Offline
                          dheerendraD Offline
                          dheerendra
                          Qt Champions 2022
                          wrote on last edited by
                          #12

                          There is no conflict. QT += GUI is to say that I would like to include this library inside the program. Also inside the main, you need to use QGUIApplication or QApplication class.

                          Dheerendra
                          @Community Service
                          Certified Qt Specialist
                          http://www.pthinks.com

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            Kien Bui
                            wrote on last edited by
                            #13

                            Is this make CLI app is larger or slower?

                            1 Reply Last reply
                            0
                            • dheerendraD Offline
                              dheerendraD Offline
                              dheerendra
                              Qt Champions 2022
                              wrote on last edited by
                              #14

                              Only performance difference is creating the QApplication object or QGUIApplicaiton object in the beginning. Since our intention is to use QStandardItemModel classes, we are forced to do this. If you totally don't want use these model classes, subclass QAbstractLitModel and implement your own data function.

                              Dheerendra
                              @Community Service
                              Certified Qt Specialist
                              http://www.pthinks.com

                              1 Reply Last reply
                              1

                              • Login

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