Results 1 to 3 of 3

Thread: simple question;QSplitter,QTreeView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default simple question;QSplitter,QTreeView

    I create a splitter QtreeView TreeModel like this:
    MainWindow::MainWindow()
    {
    ....
    ThreeModel model();

    split=new QSplitter;
    setCentralWidget(split);
    view =new QTreeView(split);
    view->setModel(&model);

    QWidget * glw = new QWidget(split);
    ....
    }
    when I run my program,my three can not display?

    but when change my code as follows,and run it,it is normal.
    main()
    {
    ......
    ThreeModel model();
    QTreeView view;
    view.setModel(&model);
    view.show();
    .....
    }
    I don't know why?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: simple question;QSplitter,QTreeView

    allocate ThreeModel in the heap using operator new.
    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3. ....
    4. ThreeModel *model = new ThreeModel();
    5.  
    6. split=new QSplitter;
    7. setCentralWidget(split);
    8. view =new QTreeView(split);
    9. view->setModel(model);
    10.  
    11. QWidget * glw = new QWidget(split);
    12. ....
    13. }
    To copy to clipboard, switch view to plain text mode 
    because your variable model will be deleted when we exitr from ctor, i.e. when out of scope will be reached.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: simple question;QSplitter,QTreeView

    Thank you for your answer.

Similar Threads

  1. Simple way to expand all nodes on a QTreeView?
    By cboles in forum Qt Programming
    Replies: 10
    Last Post: 12th April 2014, 16:54
  2. How to make a simple table and calculate col sums?
    By teele in forum Qt Programming
    Replies: 4
    Last Post: 19th January 2011, 22:34
  3. simple % curve diagram.
    By janEUcitzen in forum Qwt
    Replies: 3
    Last Post: 27th March 2009, 08:16
  4. A simple example of a tree model
    By YaK in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2009, 17:15
  5. Creating simple text editor from the eamples code
    By overcast in forum Qt Programming
    Replies: 4
    Last Post: 14th February 2007, 15:46

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
  •  
Qt is a trademark of The Qt Company.