<?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[Found interesting way to crash QML app.]]></title><description><![CDATA[<p dir="auto">I wanted to provide a function to a function as a parameter.  I also wanted the default value to be an empty function.  This however will crash if I use parameter=function(){} in the function definition:</p>
<pre><code>import QtQuick 2.15
import QtQuick.Window 2.15

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Crash QML Default Function Parameter")

    // this crashes
    function crashFunction(functionptr=function(){}){ functionptr(); }

    // this does not
    function emptyfunc(){}
    function nocrashFunction(functionptr=emptyfunc){ functionptr(); }

    // this is how I fixed it
    function nocrashFunction(functionptr=null){
        if(functionptr){
            functionptr();
        }
    }
}
</code></pre>
<p dir="auto">I solved this, but I find it interesting that it just kills the application.  I would have expected some runtime error of some sort.  I suppose this is in a top level function in the app so that exceptions are not caught by the JS engine?</p>
<p dir="auto">I don't need a fix, I just find this fascinating.</p>
]]></description><link>https://forum.qt.io/topic/131680/found-interesting-way-to-crash-qml-app</link><generator>RSS for Node</generator><lastBuildDate>Fri, 16 Oct 2026 04:46:09 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/131680.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 03 Nov 2021 17:23:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Found interesting way to crash QML app. on Fri, 05 Nov 2021 16:45:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jksh">@<bdi>JKSH</bdi></a> said in <a href="/post/688587">Found interesting way to crash QML app.</a>:</p>
<blockquote>
<p dir="auto">Would you be willing to submit a bug report to <a href="https://bugreports.qt.io/" target="_blank" rel="noopener noreferrer nofollow ugc">https://bugreports.qt.io/</a> ?</p>
</blockquote>
<p dir="auto">Yeah, I can do that.</p>
<p dir="auto"><strong>Edit:</strong><br />
<a href="https://bugreports.qt.io/browse/QTBUG-98032" target="_blank" rel="noopener noreferrer nofollow ugc">https://bugreports.qt.io/browse/QTBUG-98032</a></p>
]]></description><link>https://forum.qt.io/post/688635</link><guid isPermaLink="true">https://forum.qt.io/post/688635</guid><dc:creator><![CDATA[fcarney]]></dc:creator><pubDate>Fri, 05 Nov 2021 16:45:40 GMT</pubDate></item><item><title><![CDATA[Reply to Found interesting way to crash QML app. on Fri, 05 Nov 2021 08:22:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/fcarney">@<bdi>fcarney</bdi></a> said in <a href="/post/688292">Found interesting way to crash QML app.</a>:</p>
<blockquote>
<p dir="auto">I would have expected some runtime error of some sort.</p>
</blockquote>
<p dir="auto">Indeed; crashing is never OK.</p>
<p dir="auto">Would you be willing to submit a bug report to <a href="https://bugreports.qt.io/" target="_blank" rel="noopener noreferrer nofollow ugc">https://bugreports.qt.io/</a> ?</p>
]]></description><link>https://forum.qt.io/post/688587</link><guid isPermaLink="true">https://forum.qt.io/post/688587</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Fri, 05 Nov 2021 08:22:38 GMT</pubDate></item><item><title><![CDATA[Reply to Found interesting way to crash QML app. on Fri, 05 Nov 2021 08:02:21 GMT]]></title><description><![CDATA[<p dir="auto">Indeed, curious. The crash is in an indirect recursive call to <a href="https://code.woboq.org/qt5/qtdeclarative/src/qml/compiler/qv4codegen.cpp.html#_ZN3QV48Compiler7Codegen14defineFunctionERK7QStringPN6QQmlJS3AST4NodeEPNS6_19FormalParameterListEPNS6_13StatementListE" target="_blank" rel="noopener noreferrer nofollow ugc">QV4::Compiler::Codegen::defineFunction()</a>.</p>
<p dir="auto">Presumably this means that it is dying in the definition of the default value for <code>functionptr</code>. A simplified case triggers the same behavior:</p>
<pre><code>import QtQuick 2.15
Item {
    function crashFunction(functionptr=function(){}){ }
}
</code></pre>
<p dir="auto">Storing the function in a property is another workaround.</p>
<pre><code>property var crashFunction: function(functionptr=function(){}){ }
</code></pre>
]]></description><link>https://forum.qt.io/post/688582</link><guid isPermaLink="true">https://forum.qt.io/post/688582</guid><dc:creator><![CDATA[jeremy_k]]></dc:creator><pubDate>Fri, 05 Nov 2021 08:02:21 GMT</pubDate></item></channel></rss>