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. Making a file explorer-like interface using QFileSystemModel
Forum Updated to NodeBB v4.3 + New Features

Making a file explorer-like interface using QFileSystemModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 1.7k 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.
  • ZueukZ Offline
    ZueukZ Offline
    Zueuk
    wrote on last edited by
    #1

    Hello All,

    I wanted to have an OpenFileDialog with thumbnail previews (of my custom data format) rendering in the background, and ended up making my own version of the Windows OpenFileDialog using Qt.
    QFileSystemModel seems to be perfect for this task, however, I'm getting some random crashes and some general weirdness that questions my (and/or QFileSystemModel's) sanity.

    Here I decided to start from scratch, and recreated the file explorer part, mostly like shown in this video - and it already sometimes crashes for no apparent reason.

    dirModel = new QFileSystemModel(this);
    dirModel->setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
    dirModel->setRootPath(path);
    
    fileModel = new QFileSystemModel(this);
    fileModel->setFilter(QDir::Files);
    fileModel->setRootPath(path);
    

    I wonder, is this the correct way of using QFileSystemModel? Are we even supposed to have 2 instances of QFileSystemModel - one for dirs, and another one for files?

    Another thing: the fileModel, that is supposed to display only files, shows subfolders after I visited them - what's the purpose of fileModel->setFilter(QDir::Files) then?

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

      Hi,

      Nothing wrong with having several QFileSystemModel instances.

      However, I don't follow your last question. Can you give more details ?

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

      ZueukZ 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Nothing wrong with having several QFileSystemModel instances.

        However, I don't follow your last question. Can you give more details ?

        ZueukZ Offline
        ZueukZ Offline
        Zueuk
        wrote on last edited by
        #3

        @SGaist said in Making a file explorer-like interface using QFileSystemModel:

        However, I don't follow your last question. Can you give more details ?

        Let's say there is a "Pictures" folder, that also has some subfolders.
        When I select it first, I see only files in the fileListView - as expected. Then, on the left I click on let's say "Pictures\Screenshots", and then go back to "Pictures" again. Now, the subfolder "Screenshots" is visible in the fileListView, that is showing the data from the fileModel, that has setFilter(QDir::Files).

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

          Can you show how you handle all of that ?

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

          ZueukZ 1 Reply Last reply
          0
          • SGaistS SGaist

            Can you show how you handle all of that ?

            ZueukZ Offline
            ZueukZ Offline
            Zueuk
            wrote on last edited by Zueuk
            #5

            @SGaist it is all here

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

              The way is correct, the application is fine in that regard. Looks like a glitch of QFileSystemModel.

              It's reproducible on macOS with Qt 5.12

              Did you already check the bug report system for something similar ?

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

              ZueukZ 1 Reply Last reply
              1
              • SGaistS SGaist

                The way is correct, the application is fine in that regard. Looks like a glitch of QFileSystemModel.

                It's reproducible on macOS with Qt 5.12

                Did you already check the bug report system for something similar ?

                ZueukZ Offline
                ZueukZ Offline
                Zueuk
                wrote on last edited by
                #7

                @SGaist I didn't... then I did - OMG so much bugs in QFileSystemModel! - there's one that seems to be related to filtering, and it's open since 2010

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

                  Some bugs take more time than others to get fixed.

                  Did you open one for your issue ?

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

                  ZueukZ 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    Some bugs take more time than others to get fixed.

                    Did you open one for your issue ?

                    ZueukZ Offline
                    ZueukZ Offline
                    Zueuk
                    wrote on last edited by
                    #9

                    Did you open one for your issue ?

                    https://bugreports.qt.io/browse/QTBUG-74471

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

                      Thanks,

                      You should also attach a copy of your application to the bug report. Github might not always be present so having the report and code to reproduce the issue in the same place is better.

                      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
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved