<?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[createComponent() &#x2F; createObject() is opening new (duplicated) application]]></title><description><![CDATA[<p dir="auto">Dear all,</p>
<p dir="auto">I have this:</p>
<p dir="auto">main.qml:</p>
<pre><code>import QtQuick 2.12
import QtQuick.Controls 2.0
import 'JavaScript.js' as JS

ApplicationWindow {

    id: mainWindow
    visible: true
    width: 870
    height: 535

    property int idToDelete
    ....
}
</code></pre>
<p dir="auto">InitialScreen.qml:</p>
<pre><code>import QtQuick 2.12
import QtQuick.Controls 2.0
import 'JavaScript.js' as JS

Item {
    property int idToDelete: 0
    onIdToDeleteChanged: { JS.updateIdToDelete(idToDelete); }
    ....
}
</code></pre>
<p dir="auto">JavaScript.js:</p>
<pre><code>var component;
var sprite;
function updateIdToDelete(id) {
    component = Qt.createComponent("main.qml");
    sprite = component.createObject(mainWindow, {idToDelete: id});

    if (sprite == null) {
        // Error Handling
        console.log("Error creating object");
    }
}
</code></pre>
<p dir="auto">so my goal is, that as soon as idToDelete changes in InitialScreen.qml, via the JS script updateIdToDelete() it will update the value into main.qml as well (with same name).</p>
<p dir="auto">instead of doing so, it opens new window .exe application (even in debug mode), so i have the application window opened twice...</p>
<p dir="auto">what am I doing wrong here?</p>
]]></description><link>https://forum.qt.io/topic/116853/createcomponent-createobject-is-opening-new-duplicated-application</link><generator>RSS for Node</generator><lastBuildDate>Tue, 04 Aug 2026 12:40:37 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/116853.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 Jul 2020 13:13:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to createComponent() &#x2F; createObject() is opening new (duplicated) application on Thu, 09 Jul 2020 21:51:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/shokarta">@<bdi>shokarta</bdi></a> said in <a href="/post/605810">createComponent() / createObject() is opening new (duplicated) application</a>:</p>
<blockquote>
<p dir="auto">function updateIdToDelete(id) {<br />
component = Qt.createComponent("main.qml");<br />
sprite = component.createObject(mainWindow, {idToDelete: id});</p>
</blockquote>
<p dir="auto">you are creating your main.qml ( ApplicationWindow ) again with this code, so it is normal that it opens a new window</p>
<p dir="auto">you are trying to pass a value from InitialScreen Component to your main.qml right?<br />
How/where is your InitialScreen created ? If it is in you main.qml then you can simple do like this</p>
<p dir="auto"><a href="//main.qml" target="_blank" rel="noopener noreferrer nofollow ugc">//main.qml</a></p>
<pre><code>ApplicationWindow {
   property int idToDelete : initialScreen.idToDelete
  
  InitialScreen{
   id: initialScreen
  }
}
</code></pre>
]]></description><link>https://forum.qt.io/post/605935</link><guid isPermaLink="true">https://forum.qt.io/post/605935</guid><dc:creator><![CDATA[ODБOï]]></dc:creator><pubDate>Thu, 09 Jul 2020 21:51:04 GMT</pubDate></item><item><title><![CDATA[Reply to createComponent() &#x2F; createObject() is opening new (duplicated) application on Fri, 10 Jul 2020 07:07:20 GMT]]></title><description><![CDATA[<p dir="auto">Dude, you are the live saver...</p>
<p dir="auto">I was sortof thinking of this solution too, but I was using it like this:</p>
<pre><code>ApplicationWindow {

    id: mainWindow
    StackView {
        id: stackView
        anchors.fill: parent
        initialItem: initialScreen
    }

    Component {
        id: initialScreen
        InitialScreen {}
    }
}
</code></pre>
<p dir="auto">and this way initialScreen.idToDelete was not reachable.<br />
However redesigning code to what you suggested solved the problem :)</p>
<p dir="auto">Thank you a lot!</p>
]]></description><link>https://forum.qt.io/post/605969</link><guid isPermaLink="true">https://forum.qt.io/post/605969</guid><dc:creator><![CDATA[shokarta]]></dc:creator><pubDate>Fri, 10 Jul 2020 07:07:20 GMT</pubDate></item><item><title><![CDATA[Reply to createComponent() &#x2F; createObject() is opening new (duplicated) application on Thu, 09 Jul 2020 21:51:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/shokarta">@<bdi>shokarta</bdi></a> said in <a href="/post/605810">createComponent() / createObject() is opening new (duplicated) application</a>:</p>
<blockquote>
<p dir="auto">function updateIdToDelete(id) {<br />
component = Qt.createComponent("main.qml");<br />
sprite = component.createObject(mainWindow, {idToDelete: id});</p>
</blockquote>
<p dir="auto">you are creating your main.qml ( ApplicationWindow ) again with this code, so it is normal that it opens a new window</p>
<p dir="auto">you are trying to pass a value from InitialScreen Component to your main.qml right?<br />
How/where is your InitialScreen created ? If it is in you main.qml then you can simple do like this</p>
<p dir="auto"><a href="//main.qml" target="_blank" rel="noopener noreferrer nofollow ugc">//main.qml</a></p>
<pre><code>ApplicationWindow {
   property int idToDelete : initialScreen.idToDelete
  
  InitialScreen{
   id: initialScreen
  }
}
</code></pre>
]]></description><link>https://forum.qt.io/post/605935</link><guid isPermaLink="true">https://forum.qt.io/post/605935</guid><dc:creator><![CDATA[ODБOï]]></dc:creator><pubDate>Thu, 09 Jul 2020 21:51:04 GMT</pubDate></item></channel></rss>