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. QFileSystemModel crash when there is empty file
Forum Updated to NodeBB v4.3 + New Features

QFileSystemModel crash when there is empty file

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 600 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.
  • C Offline
    C Offline
    ChellyP
    wrote on last edited by
    #1

    Hi, I'm building a file browser with QFileSystemModel. I found that the whole application crashed when there are empty files, like a .txt file with no content in it.

    If the empty file is under the setRootPath path, the application would crash immediately when running. If the empty file is under deeper path, the application would run well and the file browser could be opened, but the application crashed when expanding the folder that the empty file is in.

    Is there any way I can fix it? By setFilter or something else? I don't need the empty file to be displayed, just want to make QFileSystemModel work with possible existing empty files.

    Thanks!

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

      Hi,

      Which version of Qt are you using ?
      On which OS ?

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

      C 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Which version of Qt are you using ?
        On which OS ?

        C Offline
        C Offline
        ChellyP
        wrote on last edited by
        #3

        @SGaist Qt 5.12.8 on Linux

        JonBJ 1 Reply Last reply
        0
        • C ChellyP

          @SGaist Qt 5.12.8 on Linux

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @ChellyP
          Can you post a very minimal example? It would be really unusual for anything to cause a "crash", it's hard to imagine an empty file would do so. Also people have used QFileSystemModel for a long time, they will surely have had some empty files, it would be pretty serious/reported if that caused such a problem.

          C 1 Reply Last reply
          0
          • JonBJ JonB

            @ChellyP
            Can you post a very minimal example? It would be really unusual for anything to cause a "crash", it's hard to imagine an empty file would do so. Also people have used QFileSystemModel for a long time, they will surely have had some empty files, it would be pretty serious/reported if that caused such a problem.

            C Offline
            C Offline
            ChellyP
            wrote on last edited by
            #5

            @JonB Thanks for your advice. I tested with the filesystembrowser example and found out the reason why QFileSystemModel with empty files crashed.

            Define application with QApplication app(argc, argv);, everything works fine.

            But define with QGuiApplication app(argc, argv);, file browser crashed when there are empty files.

            By empty files, it means files without extensions or with undefined extension and no content. For example, an empty text file with .txt extension (textFileName.txt) doesn't cause crash with QGuiApplication, but an empty text file without .txt does crash the application.

            Anyway, thanks a lot for your help.

            JonBJ 1 Reply Last reply
            0
            • C ChellyP

              @JonB Thanks for your advice. I tested with the filesystembrowser example and found out the reason why QFileSystemModel with empty files crashed.

              Define application with QApplication app(argc, argv);, everything works fine.

              But define with QGuiApplication app(argc, argv);, file browser crashed when there are empty files.

              By empty files, it means files without extensions or with undefined extension and no content. For example, an empty text file with .txt extension (textFileName.txt) doesn't cause crash with QGuiApplication, but an empty text file without .txt does crash the application.

              Anyway, thanks a lot for your help.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @ChellyP said in QFileSystemModel crash when there is empty file:

              Define application with QApplication app(argc, argv);, everything works fine.
              But define with QGuiApplication app(argc, argv);, file browser crashed when there are empty files.

              Interesting :) QApplication is supposed to be for a widget app, QGuiApplication more like for QML I think. Why the model goes wrong I do not know... I see https://stackoverflow.com/questions/49943635/qfilesystemmodel-crashing-when-seeting-root-path says

              Edit: I realize now that the problem is related to the fact, that I am using a QGuiApplication. If I use a QApplication also homePath is working.

              One issue is that QFileSystemModel requires a QApplication to run.. it says so in the detailed description

              Note: QFileSystemModel requires an instance of QApplication.

              Ah! https://doc.qt.io/qt-6/qfilesystemmodel.html#details says:

              Note: QFileSystemModel requires an instance of QApplication.

              So there is your answer :)

              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