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. I am unable to set path in QFileSystemModel
Forum Updated to NodeBB v4.3 + New Features

I am unable to set path in QFileSystemModel

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

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

    @

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fluca1978
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stima_ua
        wrote on last edited by
        #3

        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);
        @

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fluca1978
          wrote on last edited by
          #4

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

          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