<?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[How to get current file name with extension?]]></title><description><![CDATA[<p dir="auto">Does QML have a way to retrieve the current file's name? For example in Python I can simply do "<strong>file</strong>" and this would get me the name. I've tried Qt.resolvedUrl("") but it just gives undefined</p>
]]></description><link>https://forum.qt.io/topic/165142/how-to-get-current-file-name-with-extension</link><generator>RSS for Node</generator><lastBuildDate>Sat, 10 Oct 2026 05:19:43 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/165142.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 03 Oct 2026 18:13:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to get current file name with extension? on Fri, 09 Oct 2026 21:48:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kh-219design">@<bdi>KH-219Design</bdi></a> said in <a href="/post/840401">How to get current file name with extension?</a>:</p>
<blockquote>
<p dir="auto">From this older post: <a href="https://forum.qt.io/topic/122818/get-file-name-line-number-and-function-name-in-qml-javascript-how">https://forum.qt.io/topic/122818/get-file-name-line-number-and-function-name-in-qml-javascript-how</a></p>
<p dir="auto">I learned that this is possible in QML:</p>
<pre><code>  const e = new Error()
  console.log(e.stack)
</code></pre>
<p dir="auto">Sample output:</p>
<pre><code>expression for myCustomPropertyName@file:///long/path/to/my/qml/VersionLabel.qml:28
</code></pre>
<p dir="auto">The <a href="https://forum.qt.io/topic/122818/get-file-name-line-number-and-function-name-in-qml-javascript-how">older forum</a> thread has additional ideas for parsing the string if you prefer to see only a substring of what is in <code>Error().stack</code></p>
<p dir="auto">or here is how it looks when the QML file is compiled into the C++ app binary:</p>
<pre><code>expression for myCustomPropertyName@qrc:/qml/VersionLabel.qml:28
</code></pre>
</blockquote>
<p dir="auto">Took a look but it seems that if you have a file that does this and is called by another QML file it'll stack the expression to that file as well. For example if I call it from  a file called Page.qml but the error stack is called from Settings.qml I'd get</p>
<p dir="auto">Debug: expression for onCompleted@file:///Settings.qml:14<br />
expression for onCompleted@file:///Page.qml:103</p>
<p dir="auto">So I'd guess I'd need to some how parse the first line of the stack</p>
]]></description><link>https://forum.qt.io/post/840409</link><guid isPermaLink="true">https://forum.qt.io/post/840409</guid><dc:creator><![CDATA[Leooooooooo]]></dc:creator><pubDate>Fri, 09 Oct 2026 21:48:00 GMT</pubDate></item><item><title><![CDATA[Reply to How to get current file name with extension? on Fri, 09 Oct 2026 15:33:15 GMT]]></title><description><![CDATA[<p dir="auto">From this older post: <a href="https://forum.qt.io/topic/122818/get-file-name-line-number-and-function-name-in-qml-javascript-how">https://forum.qt.io/topic/122818/get-file-name-line-number-and-function-name-in-qml-javascript-how</a></p>
<p dir="auto">I learned that this is possible in QML:</p>
<pre><code>  const e = new Error()
  console.log(e.stack)
</code></pre>
<p dir="auto">Sample output:</p>
<pre><code>expression for myCustomPropertyName@file:///long/path/to/my/qml/VersionLabel.qml:28
</code></pre>
<p dir="auto">The <a href="https://forum.qt.io/topic/122818/get-file-name-line-number-and-function-name-in-qml-javascript-how">older forum</a> thread has additional ideas for parsing the string if you prefer to see only a substring of what is in <code>Error().stack</code></p>
<p dir="auto">or here is how it looks when the QML file is compiled into the C++ app binary:</p>
<pre><code>expression for myCustomPropertyName@qrc:/qml/VersionLabel.qml:28
</code></pre>
]]></description><link>https://forum.qt.io/post/840401</link><guid isPermaLink="true">https://forum.qt.io/post/840401</guid><dc:creator><![CDATA[KH-219Design]]></dc:creator><pubDate>Fri, 09 Oct 2026 15:33:15 GMT</pubDate></item></channel></rss>