<?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[Pushing to StackView with property bindings]]></title><description><![CDATA[<p dir="auto">Hello all,</p>
<p dir="auto">I've got a problem when trying to push a component to a StackView and I hope someone could clarify this.</p>
<p dir="auto">In a QML slot I push a custom component to a StackView like this:</p>
<pre><code>var deviceList = Qt.createComponent("DeviceGroups.qml");
if(deviceList.status === Component.Ready) {
    stack.push(deviceList, { "model": modelManager.locationContent } );
}
</code></pre>
<p dir="auto">DeviceGroups.qml is a customized ListView and the above code works as expected, hence the model is properly set. However it seems that no property bindings are created when setting the model like this. The ListView does not get updated when the model does. I confirmed that the relevant signal is being emitted and received in QML but the ListView doesn't care. To confirm this I tried the same with a simple text element which I update via a QML Timer like this:</p>
<pre><code>Text {
     id: testText
     text: "This is a test"
}
Timer {
     interval: 5000
     onTriggered: testText.text = testText.text + "."
     running: true
     repeat: true
}

[...]

onClicked: {
    var deviceList = Qt.createComponent("Test.qml");
    if(deviceList.status === Component.Ready) {
        stack.push(deviceList, { "text": testText.text } );
    }
}
</code></pre>
<p dir="auto">Test.qml is a simple Text item so the resulting view should be updated every time the timer triggers, or am I missing something?</p>
<p dir="auto">Thanks for any help<br />
Tobi</p>
]]></description><link>https://forum.qt.io/topic/69202/pushing-to-stackview-with-property-bindings</link><generator>RSS for Node</generator><lastBuildDate>Thu, 18 Jun 2026 08:34:30 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/69202.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 12 Jul 2016 10:01:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Pushing to StackView with property bindings on Wed, 13 Jul 2016 13:08:29 GMT]]></title><description><![CDATA[<p dir="auto">Thank you all! As soon as I created the binding, it works like a charm!<br />
And thanks to the explanation on component creation, it's now much less code! :)</p>
]]></description><link>https://forum.qt.io/post/337490</link><guid isPermaLink="true">https://forum.qt.io/post/337490</guid><dc:creator><![CDATA[MrBolton]]></dc:creator><pubDate>Wed, 13 Jul 2016 13:08:29 GMT</pubDate></item><item><title><![CDATA[Reply to Pushing to StackView with property bindings on Wed, 13 Jul 2016 12:28:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jpnurmi">@<bdi>jpnurmi</bdi></a> Thx for clarifying this! :)</p>
]]></description><link>https://forum.qt.io/post/337489</link><guid isPermaLink="true">https://forum.qt.io/post/337489</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 13 Jul 2016 12:28:43 GMT</pubDate></item><item><title><![CDATA[Reply to Pushing to StackView with property bindings on Wed, 13 Jul 2016 12:22:36 GMT]]></title><description><![CDATA[<p dir="auto"><code>StackView::push()</code> accepts <code>Items</code>, <code>Components</code>, and <code>URLs</code>. If you want to push a QML file, the most straight-forward way is to pass the URL and let <code>StackView</code> handle the rest.</p>
<p dir="auto">Passing properties to <code>StackView::push()</code> works identically with <code>Component::createObject()</code>. If you want to create a binding, you'll need to use <code>Qt.binding()</code>.</p>
<pre><code>stack.push(Qt.resolvedUrl("Button.qml"), {color: Qt.binding(function() { return foo.bar })})
</code></pre>
<p dir="auto">We'll add a note about the property bindings to the docs.</p>
]]></description><link>https://forum.qt.io/post/337488</link><guid isPermaLink="true">https://forum.qt.io/post/337488</guid><dc:creator><![CDATA[jpnurmi]]></dc:creator><pubDate>Wed, 13 Jul 2016 12:22:36 GMT</pubDate></item><item><title><![CDATA[Reply to Pushing to StackView with property bindings on Wed, 13 Jul 2016 08:38:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrbolton">@<bdi>MrBolton</bdi></a> said:</p>
<blockquote>
<p dir="auto">But is there any difference in pushing a component to the StackView or pushing an actual instance?</p>
</blockquote>
<p dir="auto">A "component" is only like a class definition in C++. See <a href="http://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html#creating-a-component-dynamically" target="_blank" rel="noopener noreferrer nofollow ugc">Creating a Component Dynamically</a>.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrbolton">@<bdi>MrBolton</bdi></a> said:</p>
<blockquote>
<p dir="auto">My problem with this is that the color of the button that is pushed onto the StackView would not get updated.<br />
Is this a bug or do I have to create the property binding myself (if yes, how) ?</p>
</blockquote>
<p dir="auto">It's not a bug, and yes, here you have to create the binding yourself. That's because <code>button.color = someThingThatChanges</code> is just a Javascript assignment. It only once copies the current value of <code>someThingThatChanges</code> to <code>button.color</code> at exactly this point of execution. If you want to create a binding from Javascript code you can do it like this:</p>
<pre><code>button.color = Qt.binding(function() { return someThingThatChanges});
</code></pre>
]]></description><link>https://forum.qt.io/post/337442</link><guid isPermaLink="true">https://forum.qt.io/post/337442</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 13 Jul 2016 08:38:41 GMT</pubDate></item><item><title><![CDATA[Reply to Pushing to StackView with property bindings on Wed, 13 Jul 2016 07:42:16 GMT]]></title><description><![CDATA[<p dir="auto">@Wieland said:</p>
<blockquote>
<p dir="auto">Hi! I didn't fully get what you're doing there but are you aware of the fact that you're only creating a component without actually instantiating an object from it?</p>
</blockquote>
<p dir="auto">Thanks for the tip. But is there any difference in pushing a component to the StackView or pushing an actual instance?</p>
<p dir="auto">To elaborate further on my problem, if I change your example a bit it might get clearer:</p>
<pre><code>var component = Qt.createComponent("Button.qml"); // only a component so far
if (component.status == Component.Ready) {
  var button = component.createObject(container); // now we have an instance
  button.color = somePropertyThatChangesOverTime;
  stack.push(button);
}
</code></pre>
<p dir="auto">My problem with this is that the color of the button that is pushed onto the StackView would not get updated.<br />
Is this a bug or do I have to create the property binding myself (if yes, how) ?</p>
<p dir="auto">Thanks in advance!</p>
]]></description><link>https://forum.qt.io/post/337438</link><guid isPermaLink="true">https://forum.qt.io/post/337438</guid><dc:creator><![CDATA[MrBolton]]></dc:creator><pubDate>Wed, 13 Jul 2016 07:42:16 GMT</pubDate></item><item><title><![CDATA[Reply to Pushing to StackView with property bindings on Tue, 12 Jul 2016 15:05:15 GMT]]></title><description><![CDATA[<p dir="auto">Hi! I didn't fully get what you're doing there but are you aware of the fact that you're only creating a component without actually instantiating an object from it? I guess your code should more look like this:</p>
<pre><code>var component = Qt.createComponent("Button.qml"); // only a component so far
if (component.status == Component.Ready) {
  var button = component.createObject(container); // now we have an instance
  button.color = "red";
}
</code></pre>
]]></description><link>https://forum.qt.io/post/337327</link><guid isPermaLink="true">https://forum.qt.io/post/337327</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 12 Jul 2016 15:05:15 GMT</pubDate></item></channel></rss>