Results 1 to 4 of 4

Thread: Good way to make a standard tree model for develop CLI and GUI application

  1. #1
    Join Date
    May 2018
    Posts
    19
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Good way to make a standard tree model for develop 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 simple tree model, 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 StandardTreeModel which I can use to devboth GUI app and CLI app

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Good way to make a standard tree model for develop CLI and GUI application

    Quote Originally Posted by madawg View Post
    But I can't using QStandardModelItemModel for develop CLI app.
    Why not?
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QStandardItemModel>
    3. #include <QDebug>
    4.  
    5. int main(int argc, char **argv) {
    6. QCoreApplication app(argc, argv);
    7. qDebug() << "No GUI here";
    8.  
    9. QStandardItemModel model(4, 4);
    10. for (int row = 0; row < 4; ++row) {
    11. for (int column = 0; column < 4; ++column) {
    12. QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column));
    13. model.setItem(row, column, item);
    14. }
    15. }
    16.  
    17. for (int row = 0; row < 4; ++row) {
    18. for (int column = 0; column < 4; ++column) {
    19. QModelIndex index = model.index(row, column);
    20. qDebug() << index.data();
    21. }
    22. }
    23.  
    24. return 0;
    25. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2018
    Posts
    19
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Good way to make a standard tree model for develop CLI and GUI application

    because I want to develop CLI app
    in .pro file, I set
    Qt Code:
    1. QT-= GUI
    To copy to clipboard, switch view to plain text mode 
    Because QStandardModelItemModel is a GUI class
    Last edited by madawg; 13th November 2018 at 03:08.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Good way to make a standard tree model for develop CLI and GUI application

    Yes, QStandardItemModel requires the QtGui library but it does not require you to use a GUI. You can have a usable command-line only application and use the standard model. It may have issues running in an environment without X though... haven't tried.

    You state you want a QAbstractItemModel interface. That interface is in QtCore so you can do this without QtGui. Take a look at Editable Tree Model Example. It is not trivial to fully implement a model, but the example goes through a working internal data structure and extensions for editing.
    Last edited by ChrisW67; 13th November 2018 at 06:24.

  5. The following user says thank you to ChrisW67 for this useful post:

    madawg (13th November 2018)

Similar Threads

  1. How to use standard model?
    By freiza in forum Newbie
    Replies: 6
    Last Post: 19th February 2015, 10:22
  2. Replies: 1
    Last Post: 29th August 2013, 06:41
  3. develop a tree.
    By tkms in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2009, 05:18
  4. QSql*Model + QTreeView : make a tree
    By punkypogo in forum Qt Programming
    Replies: 18
    Last Post: 24th October 2008, 19:14
  5. Should I develop my own model and view?
    By dandanch in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2006, 07:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.