if you want to refer to a property as 'model.i' and there are situations where 'model' doesn't exist always, it's easy to avoid error messages:
model? model.i : 42 this way you can set a default value while model is null (haven't tried this yet with Qt 5.6 but I'm doing it this way in BlackBerry 10 Cascades) ekke Am 01.04.16 um 16:05 schrieb Jérôme Godbout: > Yes, but the binding loaded object internal binding are printing > error, since the object is created without the input, then the > external binding are created. They will get eventually correct, but > the console will be filled with error message and I try to avoid that > at all cost. Here's a simple example that will complain about unable > to access i and j of undefined / assign undefined to width and height > (this example is a bit stupid but just a demo to show the problems > with more complex model and object): > > // MyComponent.qml > Item > { > property var model > width: model.i > height: model.j > } > > // Main.qml > MyModel > { > id: myModel_ > property int i: 24 > property int j: 12 > } > > Loader > { > id: loader_ > source: "MyComponent.qml" > } > > Binding > { > target: loader_.item > property: 'model' > value: myModel_ > when: loader_.status == Loader.Ready > } > > What I would like is the Loader call QQmlComponent::beginCreate(), > then having a hook to init some property then the Loader can finish > the component QQmlComponent::completeCreate(). This way I was able to > make it work, but having a custom component for that is a bit annoying. > > Loader > { > source: "MyComponent.qml" > onInitProperty: // signal emit with component object returned by > beginCreate(), > { > object.model = Qt.binding(function(){ return myModel_; }); > ... > } > } > > That seem clean and would avoid the problems to have object into bad > state for a brief moment. > > Jerome > > On Fri, Apr 1, 2016 at 12:04 AM, Shantanu Tushar <shaan...@gmail.com > <mailto:shaan...@gmail.com>> wrote: > > 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 > <jer...@bodycad.com <mailto:jer...@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@qt-project.org <mailto:Interest@qt-project.org> > http://lists.qt-project.org/mailman/listinfo/interest > > > > > -- > Shantanu Tushar (UTC +0530) > shantanu.io <http://shantanu.io> > > > > > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest