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. A simple indeed treeview does not display anything upon a correct QFileSystemModel

A simple indeed treeview does not display anything upon a correct QFileSystemModel

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 920 Views
  • 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.
  • Q Offline
    Q Offline
    qt_fan_4k
    wrote on last edited by
    #1

    It's weird that the code below does not work -- I copied almost everything from the qt4.8 example.
    I can have a window, but nothing is displayed in the treeview. It's completely blank.
    The code below is literally all I have, except main.cpp which I keep as the original.

    What I got from qDebug is 'D:/', so the model is correct.

    BTW, I tried to search for similar issues so that I don't ask silly and duplicated questions, but it seems there is no such engine to poll ...

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent)
    {
        QTreeView *treeView = new QTreeView(this);
        // set up treeview
        QFileSystemModel model;
        model.setRootPath("d:/");
        treeView->setModel(&model);
        qDebug(model.rootPath().toAscii().data());
     
        // Demonstrating look and feel features
        treeView->setAnimated(false);
        treeView->setIndentation(20);
        treeView->setSortingEnabled(true);
        this->setCentralWidget(treeView);
    }
    
    1 Reply Last reply
    0
    • D Offline
      D Offline
      Devopia53
      wrote on last edited by
      #2

      Hi

      Since you allocate your QFileSystemModel on the stack it's destroyed at the end of MainWindow constructor.

      So you allocate on the heap...

      QFileSystemModel *model = new QFileSystemModel;

      Q 1 Reply Last reply
      0
      • D Devopia53

        Hi

        Since you allocate your QFileSystemModel on the stack it's destroyed at the end of MainWindow constructor.

        So you allocate on the heap...

        QFileSystemModel *model = new QFileSystemModel;

        Q Offline
        Q Offline
        qt_fan_4k
        wrote on last edited by
        #3

        @Devopia53
        Thank you so much.
        Been playing with C++ for years and now have silly forgotten object life-cycle !
        It is now solved.

        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