[Interest] Qml Loader initial property setter

Shantanu Tushar shaan7in at gmail.com
Fri Apr 1 06:04:47 CEST 2016


Hi,

Have you tried using the QML Binding Type?
http://doc.qt.io/qt-5/qml-qtqml-binding.html

On Thu, Mar 24, 2016 at 11:11 PM, Jérôme Godbout <jerome at bodycad.com> wrote:

> 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
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>


-- 
Shantanu Tushar    (UTC +0530)
shantanu.io
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160401/8ab76a57/attachment.html>


More information about the Interest mailing list