I am unable to set path in QFileSystemModel



  • In my program i'm using tree view with a QFileSystemModel...
    But i'm unable to set a default root path in that.....
    i want to display a particular directory to display, whn program executes.....But it is showing c:, d:\ and e:\ always...
    what should i do?

    code i tried.....But its not taking that path as default....
    @
    QString sPath ="C:/Users/dmck/Desktop/folder1";

    dirmodel =new QFileSystemModel(this);
    dirmodel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);
    dirmodel->setRootPath(sPath);
    ui->treeView->setModel(dirmodel);
    

    @



  • Does the directory exists and have right permissions? What does the model states the root path is after you set it?



  • rtfm...
    @
    QModelIndex QFileSystemModel::setRootPath (const QString & newPath)
    Note: This function does not change the structure of the model or modify the data available to views. In other words, the "root" of the model is not changed to include only files and directories within the directory specified by newPath in the file system.
    @

    @
    QModelIndex rootIndex = model->setRootPath("/home");
    view->setRootIndex(rootIndex);
    @



  • I don't think the problem here is that the setRootPath does not change the view content, since the model is created from scratch....


Log in to reply
 

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