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

Making a file explorer-like interface using QFileSystemModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 1.7k Views
  • 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.
  • Z Offline
    Z Offline
    Zueuk
    wrote on 10 Feb 2019, 17:29 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 10 Feb 2019, 20:39 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

      Z 1 Reply Last reply 11 Feb 2019, 11:59
      0
      • S SGaist
        10 Feb 2019, 20:39

        Hi,

        Nothing wrong with having several QFileSystemModel instances.

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

        Z Offline
        Z Offline
        Zueuk
        wrote on 11 Feb 2019, 11:59 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 11 Feb 2019, 22:26 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

          Z 1 Reply Last reply 12 Feb 2019, 14:30
          0
          • S SGaist
            11 Feb 2019, 22:26

            Can you show how you handle all of that ?

            Z Offline
            Z Offline
            Zueuk
            wrote on 12 Feb 2019, 14:30 last edited by Zueuk 2 Dec 2019, 20:02
            #5

            @SGaist it is all here

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 15 Feb 2019, 23:17 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

              Z 1 Reply Last reply 17 Feb 2019, 14:03
              1
              • S SGaist
                15 Feb 2019, 23:17

                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 ?

                Z Offline
                Z Offline
                Zueuk
                wrote on 17 Feb 2019, 14:03 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
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 17 Feb 2019, 18:10 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

                  Z 1 Reply Last reply 15 Mar 2019, 17:11
                  1
                  • S SGaist
                    17 Feb 2019, 18:10

                    Some bugs take more time than others to get fixed.

                    Did you open one for your issue ?

                    Z Offline
                    Z Offline
                    Zueuk
                    wrote on 15 Mar 2019, 17:11 last edited by
                    #9

                    Did you open one for your issue ?

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

                    1 Reply Last reply
                    1
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 15 Mar 2019, 21:41 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