<?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[Need help on deciding best approach]]></title><description><![CDATA[<p dir="auto">Hi,<br />
Following is a code snippet. I have mentioned 2 approaches of showing a text field data depending on a property.</p>
<pre><code>Window {
    id: win
    visible: true
    width: 800
    height: 480
    title: qsTr("Hello World")
    property string progressFillType: "TEXT_4"

//Option1
    Text {
        text: progressFillType === "TEXT_1" ? "ABCF" : (progressFillType === "TEXT_2" ? "EFGH" : (progressFillType === "TEXT_3" ? "IJKL" : "MNOP"))
    }


//Option2
//    property var progressFillColorMap : {"TEXT_1" : {color: "ABCF"},
//                                         "TEXT_2" : {color: "EFGH"},
//                                         "TEXT_3" : {color: "IJKL"},
//                                         "TEXT_4" : {color: "MNOP"}
//                                        }
//    Text {
//        text:
//            progressFillColorMap[progressFillType].color
//    }

}
</code></pre>
<p dir="auto">Please let me know which is a better approach, if I am writing for some embedded device?</p>
]]></description><link>https://forum.qt.io/topic/117902/need-help-on-deciding-best-approach</link><generator>RSS for Node</generator><lastBuildDate>Mon, 03 Aug 2026 00:40:31 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/117902.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 11 Aug 2020 09:37:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Need help on deciding best approach on Tue, 11 Aug 2020 16:54:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bikashrdas">@<bdi>BikashRDas</bdi></a> Hi,<br />
Personnally for this case I would keep it in the qml for convenience, or put it in javascript  (to make the code more readable).<br />
In the projet we are doing we keep in c++: networking, files managments, Downloadmanager etc. The rest is done in js/qml as it is quicker to write and easier to maintain.</p>
]]></description><link>https://forum.qt.io/post/611652</link><guid isPermaLink="true">https://forum.qt.io/post/611652</guid><dc:creator><![CDATA[Allon]]></dc:creator><pubDate>Tue, 11 Aug 2020 16:54:27 GMT</pubDate></item><item><title><![CDATA[Reply to Need help on deciding best approach on Tue, 11 Aug 2020 14:47:19 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/allon">@<bdi>Allon</bdi></a>,<br />
I more question. Having this map implementation in a C++ class and accessing information from the same using Q_INVOKABLE methods, is it a good idea? Or it is better to have the map implementation in the QML context only as mentioned in above example?</p>
]]></description><link>https://forum.qt.io/post/611630</link><guid isPermaLink="true">https://forum.qt.io/post/611630</guid><dc:creator><![CDATA[BikashRDas]]></dc:creator><pubDate>Tue, 11 Aug 2020 14:47:19 GMT</pubDate></item><item><title><![CDATA[Reply to Need help on deciding best approach on Tue, 11 Aug 2020 13:11:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bikashrdas">@<bdi>BikashRDas</bdi></a> Speed could depend of how fast the condition is found.<br />
Map will always take the same time as it follows the same logic.<br />
Conditional expression in your case can fail several time before to match the right condition depending of the value to check.<br />
Easy test would be to provide TEXT_4 a lots of time (10000 ?), then TEXT_1. I am quite sure that TEXT_1 would be quicker.</p>
]]></description><link>https://forum.qt.io/post/611604</link><guid isPermaLink="true">https://forum.qt.io/post/611604</guid><dc:creator><![CDATA[Allon]]></dc:creator><pubDate>Tue, 11 Aug 2020 13:11:53 GMT</pubDate></item><item><title><![CDATA[Reply to Need help on deciding best approach on Tue, 11 Aug 2020 13:11:03 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/allon">@<bdi>Allon</bdi></a>,<br />
The map is actually taking the space, which is around 320 byte. The assignment expression of text value by reading the data from map is actually taking very less space (64 bytes), in comparison to the conditional statement in the option 1 (227 byte).<br />
Yes you are right. 1k is not a big size. And I am sure the map way implementation will definitely help in reducing the number of lines of the JS code (like handlers, functions and conditional checks).</p>
]]></description><link>https://forum.qt.io/post/611603</link><guid isPermaLink="true">https://forum.qt.io/post/611603</guid><dc:creator><![CDATA[BikashRDas]]></dc:creator><pubDate>Tue, 11 Aug 2020 13:11:03 GMT</pubDate></item><item><title><![CDATA[Reply to Need help on deciding best approach on Tue, 11 Aug 2020 13:00:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bikashrdas">@<bdi>BikashRDas</bdi></a> 1k is not that much even for embedded nowadays. However it seems strange that a map takes some much more space than a conditional evaluation!</p>
]]></description><link>https://forum.qt.io/post/611597</link><guid isPermaLink="true">https://forum.qt.io/post/611597</guid><dc:creator><![CDATA[Allon]]></dc:creator><pubDate>Tue, 11 Aug 2020 13:00:40 GMT</pubDate></item><item><title><![CDATA[Reply to Need help on deciding best approach on Tue, 11 Aug 2020 11:02:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/allon">@<bdi>Allon</bdi></a> Hi,<br />
Thank you very much for the reply. I too believe that option 2 is more maintainable and readable. But when I am checking it on the QML Profiler, I am seeing <strong>option 2</strong> is holding 1k bytes more than <strong>option 1</strong>.<br />
A general observation, in majority of the cases option 2 is starting bit faster than option 1 (as observed in QML profiler). But 5% of cases it is reverse. So not able to understand if we can consider the option 2 a bit space consuming but faster way of handing the scenario above or not.</p>
]]></description><link>https://forum.qt.io/post/611586</link><guid isPermaLink="true">https://forum.qt.io/post/611586</guid><dc:creator><![CDATA[BikashRDas]]></dc:creator><pubDate>Tue, 11 Aug 2020 11:02:41 GMT</pubDate></item><item><title><![CDATA[Reply to Need help on deciding best approach on Tue, 11 Aug 2020 10:09:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bikashrdas">@<bdi>BikashRDas</bdi></a> Hi,<br />
I do not know about performances  but option2 is so much more maintainable and readable that I go for it without any doubt.<br />
Even if option2 would take 10 times more time than option 1, something you have to take in account is how often it is called.<br />
As it displays text I have no doubt that this is not called so often, so I would definitely go for option 2.<br />
Emmanuel</p>
]]></description><link>https://forum.qt.io/post/611582</link><guid isPermaLink="true">https://forum.qt.io/post/611582</guid><dc:creator><![CDATA[Allon]]></dc:creator><pubDate>Tue, 11 Aug 2020 10:09:45 GMT</pubDate></item></channel></rss>