Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

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



  • 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


  • Qt Champions 2017

    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 ?



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



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


  • Qt Champions 2017

    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.



  • This post is deleted!


  • @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,...


  • Qt Champions 2017

    Are you using QFileSystemModel for the same ?



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


  • Qt Champions 2017

    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.



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


  • Qt Champions 2017

    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.



  • Is this make CLI app is larger or slower?


  • Qt Champions 2017

    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.


Log in to reply