Results 1 to 1 of 1

Thread: <solved> simple tree model now working in mu apllication

  1. #1
    Join Date
    Oct 2011
    Posts
    51
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default <solved> simple tree model now working in mu apllication

    Hi!
    I want to create a simple tree model, so i decided to use http://qt-project.org/doc/qt-5/qtwid...l-example.html example and modify it to fit my needs. But after creating MainWindow and QTreeView in it using QtDesigner this example stooped working :| I assume that this happens because some kind of configuration of myTreeView, but I don't know witch.

    Qt Code:
    1. #include "../../../../opt/Qt/5.2.0/gcc_64/examples/widgets/itemviews/simpletreemodel/treemodel.h"
    2.  
    3. MainWindow::MainWindow(QWidget *parent) :
    4. QMainWindow(parent),
    5. ui(new Ui::MainWindow)
    6. {
    7. ui->setupUi(this);
    8.  
    9. QFile file("/home/sti/default.txt");
    10. file.open(QIODevice::ReadOnly);
    11. TreeModel model(file.readAll());
    12. file.close();
    13. ui->myTreeView->setModel(&model);
    14. ui->myTreeView->show();
    15. }
    To copy to clipboard, switch view to plain text mode 

    As you can see TableModel is taken directly from the examples, so I didn't modify them in any way.... file default.txt is available and it is a copy of file in this example
    What I'm missing?


    *** Edit *****

    My problem was that model is a local variable and it's live ends when MainWindow constructor ends... So I need to change that to

    Qt Code:
    1. QFile file("/home/sti/default.txt");
    2. file.open(QIODevice::ReadOnly);
    3. TreeModel *model = new TreeModel(file.readAll());
    4. file.close();
    5.  
    6.  
    7. ui->treeOfGroups->setModel(model);
    8. ui->treeOfGroups->show();
    To copy to clipboard, switch view to plain text mode 

    A stupid mistake
    Last edited by cszawisza; 3rd May 2014 at 11:46.

Similar Threads

  1. How to use "Simple Tree Model" Example?
    By Markus in forum Newbie
    Replies: 2
    Last Post: 28th January 2014, 02:37
  2. Replies: 1
    Last Post: 29th August 2013, 05:41
  3. Replies: 1
    Last Post: 7th July 2009, 07:13
  4. A simple example of a tree model
    By YaK in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2009, 17:15
  5. using the example of simple tree model
    By krishna.bv in forum Qt Programming
    Replies: 1
    Last Post: 22nd December 2006, 12:28

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.