<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QFileSystemModel crash when there is empty file]]></title><description><![CDATA[<p dir="auto">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.</p>
<p dir="auto">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.</p>
<p dir="auto">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.</p>
<p dir="auto">Thanks!</p>
]]></description><link>https://forum.qt.io/topic/138616/qfilesystemmodel-crash-when-there-is-empty-file</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Apr 2026 20:17:23 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/138616.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 15 Aug 2022 18:41:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QFileSystemModel crash when there is empty file on Mon, 15 Aug 2022 20:45:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chellyp">@<bdi>ChellyP</bdi></a> said in <a href="/post/724950">QFileSystemModel crash when there is empty file</a>:</p>
<blockquote>
<p dir="auto">Define application with QApplication app(argc, argv);, everything works fine.<br />
But define with QGuiApplication app(argc, argv);, file browser crashed when there are empty files.</p>
</blockquote>
<p dir="auto">Interesting :)  <code>QApplication</code> is supposed to be for a widget app, <code>QGuiApplication</code> more like for QML I think.  Why the <em>model</em> goes wrong I do not know... I see <a href="https://stackoverflow.com/questions/49943635/qfilesystemmodel-crashing-when-seeting-root-path" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/49943635/qfilesystemmodel-crashing-when-seeting-root-path</a> says</p>
<blockquote>
<p dir="auto">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.</p>
</blockquote>
<blockquote>
<p dir="auto">One issue is that QFileSystemModel requires a QApplication to run.. it says so in the detailed description</p>
<p dir="auto">Note: QFileSystemModel requires an instance of QApplication.</p>
</blockquote>
<p dir="auto">Ah!  <a href="https://doc.qt.io/qt-6/qfilesystemmodel.html#details" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qfilesystemmodel.html#details</a> says:</p>
<blockquote>
<p dir="auto"><strong>Note</strong>: QFileSystemModel requires an instance of QApplication.</p>
</blockquote>
<p dir="auto">So there is your answer :)</p>
]]></description><link>https://forum.qt.io/post/724952</link><guid isPermaLink="true">https://forum.qt.io/post/724952</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 15 Aug 2022 20:45:55 GMT</pubDate></item><item><title><![CDATA[Reply to QFileSystemModel crash when there is empty file on Mon, 15 Aug 2022 20:37:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> Thanks for your advice. I tested with the filesystembrowser example and found out the reason why <code>QFileSystemModel</code> with empty files crashed.</p>
<p dir="auto">Define application with <code>QApplication app(argc, argv);</code>, everything works fine.</p>
<p dir="auto">But define with <code>QGuiApplication app(argc, argv);</code>, file browser crashed when there are empty files.</p>
<p dir="auto">By <em>empty files</em>, it means files without extensions or with undefined extension <em>and</em> no content. For example, an empty text file with .<em>txt</em> extension (<em>textFileName</em>.<em>txt</em>) doesn't cause crash with <code>QGuiApplication</code>, but an empty text file without .<em>txt</em> does crash the application.</p>
<p dir="auto">Anyway, thanks a lot for your help.</p>
]]></description><link>https://forum.qt.io/post/724950</link><guid isPermaLink="true">https://forum.qt.io/post/724950</guid><dc:creator><![CDATA[ChellyP]]></dc:creator><pubDate>Mon, 15 Aug 2022 20:37:28 GMT</pubDate></item><item><title><![CDATA[Reply to QFileSystemModel crash when there is empty file on Mon, 15 Aug 2022 19:02:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chellyp">@<bdi>ChellyP</bdi></a><br />
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 <code>QFileSystemModel</code> for a long time, they will surely have had some empty files, it would be pretty serious/reported if that caused such a problem.</p>
]]></description><link>https://forum.qt.io/post/724941</link><guid isPermaLink="true">https://forum.qt.io/post/724941</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 15 Aug 2022 19:02:16 GMT</pubDate></item><item><title><![CDATA[Reply to QFileSystemModel crash when there is empty file on Mon, 15 Aug 2022 18:59:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> Qt 5.12.8 on Linux</p>
]]></description><link>https://forum.qt.io/post/724939</link><guid isPermaLink="true">https://forum.qt.io/post/724939</guid><dc:creator><![CDATA[ChellyP]]></dc:creator><pubDate>Mon, 15 Aug 2022 18:59:41 GMT</pubDate></item><item><title><![CDATA[Reply to QFileSystemModel crash when there is empty file on Mon, 15 Aug 2022 18:57:50 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Which version of Qt are you using ?<br />
On which OS ?</p>
]]></description><link>https://forum.qt.io/post/724938</link><guid isPermaLink="true">https://forum.qt.io/post/724938</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 15 Aug 2022 18:57:50 GMT</pubDate></item></channel></rss>