Making a file explorer-like interface using QFileSystemModel



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


  • Lifetime Qt Champion

    Hi,

    Nothing wrong with having several QFileSystemModel instances.

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



  • @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).


  • Lifetime Qt Champion

    Can you show how you handle all of that ?



  • @SGaist it is all here


  • Lifetime Qt Champion

    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 ?


Log in to reply
 

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