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

  • 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) :
        QTreeView *treeView = new QTreeView(this);
        // set up treeview
        QFileSystemModel model;
        // Demonstrating look and feel features

  • 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;

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.