Loader child element
-
Hi,
I try to access a loader and assign a source file dynamically using JavaScript. That works fine so far.
But now I need to set some properties of the item I loaded to the loader element.The problem is I don't know how to access the element that was instantiated by the loader.
Is there some kind of child or whatever property that I can refer to.Thanks for help guys
-
Oh boy...
Ok another problem occurred.
I have the following procedure.
The qml item which should be instantiated.
@import QtQuick 1.0
import Product 0.1Item{
id:detail_screen
anchors.fill: parentproperty alias product: m_product
Text {
id: name
anchors.fill: parent
text: m_product.productName
}Product{
id: m_product
productName: "foo"} Component.onCompleted:
console.log(product.productName);
}@
and the JavaScript function which do that for me.
@
function loadDetailScreen(source,product)
{
console.log(source);
select_loader.source = source; //load the qml file shown above
if(select_loader.status == Loader.Ready)
{
select_loader.item.product.productName = "bar";
}
console.log(select_loader.item.product.productName); //that actually shows "bar"
}
@When the loadDetailScreen() function is called the loader instantiates the qml item
which initially has a productName "foo". But I wanna set this productName after loading to "bar"
This works pretty well so far. But on screen appears still "foo" as text.I tried to set a string property which takes the productName and this worked, but I wanna store these informations directly in the product child item.
It seems like that the change on the productName property won't be synchronized with the text, which has to display it.
What could be the problem here ?
Why does the item show still "foo" although I set it to "bar" after loading ?Any ideas ?
-
-
Sorry, my mistake - I meant to write, it does indeed change to "bar" instead of "foo".
This is the code that I'm trying:
- SomeItem.qml
@
import QtQuick 1.0
Item {
property alias product: m_productText { text: m_product.productName } Item { id: m_product property string productName: "foo" }
}
@- main.qml
@
import QtQuick 1.0
Item {
width: 400; height: 400Loader { id: select_loader } Component.onCompleted: loadDetailScreen("SomeItem.qml") function loadDetailScreen(source) { console.log(source); select_loader.source = source; //load the qml file shown above if(select_loader.status == Loader.Ready) { select_loader.item.product.productName = "bar"; } console.log(select_loader.item.product.productName); //that actually shows "bar" }
}
@ - SomeItem.qml