Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]QFileSystemModel set root path
Qt 6.12 LTS is out! See what's new in the release blog

[SOLVED]QFileSystemModel set root path

Scheduled Pinned Locked Moved General and Desktop
20 Posts 5 Posters 19.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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #11

    *@@

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #12

      @QFileSystemModel* fsModel = new QFileSystemModel(this);
      fsModel->setRootPath("c:/file qt/");
      fsModel->setReadOnly(true);
      fsModel->setFilter(QDir::AllDirs | QDir::AllEntries |QDir::NoDotAndDotDot);
      QStringList filter;
      filter<<"*.txt";
      fsModel->setNameFilters(filter);@

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #13

        No need to post your code again, you can simply edit your answer to add the coding tags

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • saeedhardanS Offline
          saeedhardanS Offline
          saeedhardan
          wrote on last edited by
          #14

          [quote author="SGaist" date="1413280688"]You need to also call setRootIndex in your tree view. You have the details in the documentation from QFileSystemModel[/quote]

          now it works , thanks a lot , all i added was :
          @
          ui->treeView->setRootIndex(files->index(fPath));
          @
          after you set the tree view model

          1 Reply Last reply
          1
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #15

            I'm sorry . are new .

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #16

              You're welcome !

              No problem, everybody falls for that one ;)

              Happy coding !

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #17

                If you are using treeview can also try qDirModel
                @ QStringList filters;
                filters << "*.txt";
                model = new QDirModel(this);
                model->setReadOnly(false);
                model->setReadOnly(true);
                model->setSorting(QDir::DirsFirst |QDir::IgnoreCase | QDir::Type);
                model->setFilter(QDir::AllDirs | QDir::AllEntries |QDir::NoDotAndDotDot);
                model->setNameFilters(filters);

                ui->treeViewDirectory->setModel(model);
                QModelIndex index=model->index("C:/file qt/");
                ui->treeViewDirectory->expand(index);
                ui->treeViewDirectory->scrollTo(index);@
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #18

                  QDirModel has been obsoleted, QFileSystemModel is the right class to use

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #19

                    ok ok

                    1 Reply Last reply
                    0
                    • terma.abaT Offline
                      terma.abaT Offline
                      terma.aba
                      wrote on last edited by
                      #20

                      What if the view is QML ListView and has no setRootIndex()?

                      QFileSystemModel is badly designed, it makes wrong assumptions on functions you have to be able to call on the view.

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