Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sample Code of SimpleTreeModel
Qt 6.11 is out! See what's new in the release blog

Sample Code of SimpleTreeModel

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I try to use this code in my App.

    @QFile file(":/default.txt");
    file.open(QIODevice::ReadOnly);
    TreeModel model(file.readAll());
    file.close();

    QTreeView view;
    view.setModel(&model);
    view.setWindowTitle(QObject::tr("Simple Tree Model"));
    view.show();@

    when I paste it in main then code works (I see QTreeView with data), but when paste it in QMainWindow constructor then I see an empty QTreeView window without data.

    why?

    !http://s3.amazonaws.com/twitpic/photos/full/202748685.jpg?AWSAccessKeyId=0ZRYP5X5F6FSMBCCSE82&Expires=1291443830&Signature=SHKQpEbG1EvKJh465qz76IiKSs4=(pic)!

    1 Reply Last reply
    0
    • B Offline
      B Offline
      blex
      wrote on last edited by
      #2

      QTreeModel and QTreeView are destroyed when QMainWindow constructor is finished. Use "new" to create these objects


      Oleksiy Balabay

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        ups!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved