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. [Solved]QTreeView based on MVC Pattern
Forum Updated to NodeBB v4.3 + New Features

[Solved]QTreeView based on MVC Pattern

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.2k 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.
  • P Offline
    P Offline
    Peggy
    wrote on last edited by
    #1

    Hello everyone,

    I read some articles about MVC, better to say MV, design pattern in Qt and used the Simple Tree Model example which is existed as an example in Qt_Examples in my program.

    My proram is a MainWindow with different parts and functions. I put the Tree in the QTabWidget:
    @
    QTabWidget tabWidget = new QTabWidget;
    tabWidget->addTab(new GeneralTab(), tr("General"));

    //The writen code in GeneralTab class
    QFile file(":/default.txt");
    file.open(QIODevice::ReadOnly);
    TreeModel model(file.readAll());
    file.close();

    QTreeView* treeView = new QTreeView;
    treeView->setModel(&model);
    
    QVBoxLayout* treeLayout = new QVBoxLayout;
    treeLayout->addWidget(treeView);
    
     setLayout( treeLayout);
    

    @

    The problem is nothing will be showen, in my tab!!! even no error message!

    I am looking forward to the suggestions esp. solutions:)

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi,

      your model is a stack variable, which means, it will be deleted on method end.
      Make it a heap object created with new :-)

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Don't worry, it's a classic mistake :-)

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Peggy
          wrote on last edited by
          #4

          Thank you. It works now:)

          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