Solved Good way to make a standard tree model to develop both CLI and GUI application
-
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 -
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,... -
Are you using QFileSystemModel for the same ?
-
@dheerendra
But QFileSystemModel is a GUI class.
Plus, How to import from json API to QFileSystemModel -
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. -
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?
-
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.