[Interest] Qml Loader initial property setter
Sina Dogru
sinadooru at gmail.com
Thu Apr 14 08:51:26 CEST 2016
It actually seems like doable. As documented section "QVariantList and
QVariantMap to JavaScript Array and Object" on the "Data Type Conversion
Between QML and C++ <http://doc.qt.io/qt-5/qtqml-cppintegration-data.html>",
"passing a QVariantList
<http://doc.qt.io/qt-5/qvariant.html#QVariantList-typedef> and a QVariantMap
<http://doc.qt.io/qt-5/qvariant.html#QVariantMap-typedef>, which are
automatically converted to JavaScript array and object values, repectively"
So I assume it is possible to implement "initialProperties" property for
QQuickLoader class, like on the commit
<https://codereview.qt-project.org/#/c/3072/> of the old Qt days. But why
no one have implemented it before, it disorienting. It might requires more
knowledge then this?
2016-04-13 16:17 GMT+03:00 Jérôme Godbout <jerome at bodycad.com>:
> I agree, this would be difficult to know if this should create a binding
> or simply copy the current value. This is why I was proposing the function
> where we could go with either = or Qt.binding() to have full control on
> it. Nice to see this was there at some point, I wonder why they removed it
> or never integrate it.
>
> On Wed, Apr 13, 2016 at 2:07 AM, Sina Dogru <sinadooru at gmail.com> wrote:
>
>> It's sad that the imperative setSource() function can set those property
>>> and the declarative way is not.
>>>
>>
>> It would also be great but to make something a property instead of a
>> function where it is much easier, then there should be a public and
>> QMetaType known type.Thats why seems like hard to make it possible.
>>
>> 2016-04-04 16:31 GMT+03:00 Jérôme Godbout <jerome at bodycad.com>:
>>
>>> Thanks for pointing this out, but I was aware of that. Sometime a
>>> default value is impossible (null) making bad behavior or bad binding,
>>> primitive type can always have default value that make sense that way but
>>> complex object don't.
>>> It's sad that the imperative setSource() function can set those property
>>> and the declarative way is not.
>>>
>>> On Sun, Apr 3, 2016 at 11:10 AM, ekke <ekke at ekkes-corner.org> wrote:
>>>
>>>> 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 <shaan7in at gmail.com>
>>>> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> Have you tried using the QML Binding Type?
>>>>> <http://doc.qt.io/qt-5/qml-qtqml-binding.html>
>>>>> 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>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
>>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Interest mailing listInterest at qt-project.orghttp://lists.qt-project.org/mailman/listinfo/interest
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Interest mailing list
>>>> Interest at qt-project.org
>>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>>
>>>>
>>>
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160414/16d16b64/attachment.html>
More information about the Interest
mailing list