[Interest] Qml Loader initial property setter
Jérôme Godbout
jerome at bodycad.com
Thu Mar 24 18:41:49 CET 2016
Hi,
I was wondering if I am the only one who found the initial property of a
source based Loader Item a bit annoying. inline sourceComponent with
Component {} declaration are well ok on the other hand. I'm explaining
myself, when using a loader you have 2 choice to set the initial binding on
created item:
1- On item changed set the binding
*Loader*
*{*
* source: externalObj.getSrc() // return something like "myItem.qml"*
* onItemChanged:*
* {*
* if(!item) return;*
* item.myprop = Qt.binding(function(){ return myExternalProperty; })*
* }*
*}*
2- use the setSource() function instead of the source directly
*Loader*
*{*
* property url myDummySrc: externalObj.getSrc()*
* onMyDummySrcChanged:*
* {*
* setSource(myDummySrc, { 'myprop': Qt.binding(function(){ return
myExternalProperty; }) });*
* }*
*}*
This is rather annoying and ugly. Number 1 is also having the problem where
*myItem.qml* must be able to handle *myprop *to have a default value or
being empty without output a lots of console error. Number 2 work well and
is the solution I find myself writing often. I was wondering if a Loader
that support a dictionary of initial property when source changed would be
nice:
*Loader*
*{*
* source: externalObj.getSrc()*
* initialProperties: { 'myprop': Qt.binding(function(){ return
myExternalProperty; }) }*
*}*
What do you think?
Jerome
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160324/8791b18e/attachment.html>
More information about the Interest
mailing list