<?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[Acessing childrens by ID?]]></title><description><![CDATA[<p dir="auto">Hello as... as I have complex:</p>
<p dir="auto">main.qml:</p>
<pre><code>ApplicationWindow {
    id: mainWindow

    // here is where i need to get the TextFiled text set as "something"

    // Views (initialy used SwipeView)
    StackLayout {
        id: view
        anchors.fill: parent
        currentIndex: 0

        Item {
            id: view_InitialScreen
            InitialScreen {}
        }
        Item {
            id: view_ChoiseOffline
            ChoiseOffline {}
        }
    }
}
</code></pre>
<p dir="auto">ChooseOffline.qml:</p>
<pre><code>Rectangle {
    id: parentObject
    anchors.fill: parent

    Rectangle {
        id: testRect

        Rectangle {
            id: preselectedStrloRectangle

            Rectangle {
                id: scanRectangle

                Image {
                    id: scanImage
                }
            }

            Rectangle {
                id: preselectedStrloRectangle1

                Label {
                    id: preselectedStrloLabel1
                }
            }
            Rectangle {
                id: preselectedStrloRectangle2

                TextField {
                    id: preselectedStrloTextfield2
                    text: "something"
                }
            }
            Rectangle {
                id: preselectedStrloRectangle3

                Image {
                    id: clearImage
                }
            }
        }

        Rectangle {
            id: serialNumberRectangle

            Rectangle {
                id: serialNumberRectangle1

                Label {
                    id: serialNumberLabel1
                }
            }
            Rectangle {
                id: serialNumberRectangle2

                TextField {
                    id: serialNumberTextfield2
                }
            }
        }

	... and so on
}
</code></pre>
<p dir="auto">so far the only way I was able to console.log() the text value is by:</p>
<pre><code>console.log(view_ChoiseOffline.children[0].children[0].children[0].children[2].children[0].text)
</code></pre>
<p dir="auto">but this is a terrible solution as Im keep adjuting the code, adding more childrens above and bellow so this would constantly change...</p>
<p dir="auto">everytime i try to use IDs instead of children[int] i get an error that Cannot read property xxxx of undefined.<br />
i have tried to use difenret id name instead of children[0], or simply children[parentObject]/children['parentObject'] or ucing "item" instead of "children".</p>
<p dir="auto">so is there any way to access it simply by ID(s) out of the main.qml?</p>
]]></description><link>https://forum.qt.io/topic/139250/acessing-childrens-by-id</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 15:04:25 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139250.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 12 Sep 2022 11:50:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Acessing childrens by ID? on Tue, 13 Sep 2022 13:17:05 GMT]]></title><description><![CDATA[<p dir="auto">how about:</p>
<p dir="auto">main.qml:</p>
<pre><code>ApplicationWindow {
    id: mainWindow

    // here is where i need to get the TextFiled text set as "something"

    // Views (initialy used SwipeView)
    StackLayout {
        id: view
        anchors.fill: parent
        currentIndex: 0

        Item {
            id: view_InitialScreen
            InitialScreen {}
        }
        Item {
            id: view_ChoiseOffline
            ChoiseOffline {id:chOffline;}
        }
    }
}
</code></pre>
<p dir="auto">ChooseOffline.qml:</p>
<pre><code>Rectangle {
    id: parentObject
    anchors.fill: parent
   property alias aliasPreselectedLocation: preselectedStrloTextfield2
....
}
</code></pre>
<pre><code>console.log(chOffline.aliasPreselectedLocation.text)
</code></pre>
]]></description><link>https://forum.qt.io/post/728565</link><guid isPermaLink="true">https://forum.qt.io/post/728565</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Tue, 13 Sep 2022 13:17:05 GMT</pubDate></item><item><title><![CDATA[Reply to Acessing childrens by ID? on Tue, 13 Sep 2022 06:24:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/marko-stanke">@<bdi>Marko-Stanke</bdi></a> said in <a href="/post/728406">Acessing childrens by ID?</a>:</p>
<blockquote>
<p dir="auto">What you could do is inside of your ChooseOffline.qml and inside of parentObject, define an alias for the text you want to access:</p>
<p dir="auto">property alias preselectedTextfield: preselectedStrloTextfield2</p>
<p dir="auto">and then from main.qml you can access it with view_ChoiseOffline.preselectedTextfield.text</p>
</blockquote>
<p dir="auto">well this does not work... however what I have managed to make it work is to set the alias inside <em><strong>parentObject</strong></em>:</p>
<pre><code>property alias aliasPreselectedLocation: preselectedStrloTextfield2
</code></pre>
<p dir="auto">which Im able to call from <em><strong>mainWindow</strong></em> via:</p>
<pre><code>view_ChoiseOffline.children[0].aliasPreselectedLocation.text
</code></pre>
<p dir="auto">definitely not nice way, but at least it works...</p>
<p dir="auto">but back to my question... can I use children with string value (of ID idealy) instead of integer counter?<br />
something like:</p>
<pre><code>children['parentObject']
</code></pre>
<p dir="auto">I tried several ways but i have never made it work</p>
]]></description><link>https://forum.qt.io/post/728465</link><guid isPermaLink="true">https://forum.qt.io/post/728465</guid><dc:creator><![CDATA[shokarta]]></dc:creator><pubDate>Tue, 13 Sep 2022 06:24:18 GMT</pubDate></item><item><title><![CDATA[Reply to Acessing childrens by ID? on Mon, 12 Sep 2022 15:04:35 GMT]]></title><description><![CDATA[<p dir="auto">What you could do is inside of your ChooseOffline.qml and inside of parentObject, define an alias for the text you want to access:</p>
<p dir="auto">property alias preselectedTextfield: preselectedStrloTextfield2</p>
<p dir="auto">and then from main.qml you can access it with view_ChoiseOffline.preselectedTextfield.text</p>
]]></description><link>https://forum.qt.io/post/728406</link><guid isPermaLink="true">https://forum.qt.io/post/728406</guid><dc:creator><![CDATA[Marko Stanke]]></dc:creator><pubDate>Mon, 12 Sep 2022 15:04:35 GMT</pubDate></item><item><title><![CDATA[Reply to Acessing childrens by ID? on Mon, 12 Sep 2022 14:30:51 GMT]]></title><description><![CDATA[<p dir="auto">set objectName to the children. Then something like this?</p>
<pre><code>     for(var i = 0; i &lt; view_ChoiceOffline.children.length; ++i)
         if(view_ChoiceOffline.children[i].objectName==="something"){
              console.log(view_ChoiceOffline.children[i].text)
         }
     }
</code></pre>
]]></description><link>https://forum.qt.io/post/728401</link><guid isPermaLink="true">https://forum.qt.io/post/728401</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Mon, 12 Sep 2022 14:30:51 GMT</pubDate></item></channel></rss>