[Interest] create delegate modelData

Jérôme Godbout jerome at bodycad.com
Tue Jul 19 13:31:15 CEST 2016


modelData is a variable set into the context of the created component.
Therefore, it does not exist into the Repeater until the object is
instanciated. It's the Repeater itself that create a new context based on
it's context and push variables into the object instance context.

2 variables are set into Repeater instanciatede object context: index and
modelData
As a good pratice, you should avoid using those name as property name to
avoid either context problems and also avoid confusion with other developer.

see for example how to set property into a context:
http://doc.qt.io/qt-5/qtqml-cppintegration-contextproperties.html



On Mon, Jul 18, 2016 at 7:35 PM, Kevin Mcintyre <kebin70 at gmail.com> wrote:

> Thanks for the follow up -
>
> I quickly discovered a mistake in my thinking that createObject sets
> properties not objects so of course modelData object will not working out
> of box because it's passed into delegates as an object.
>
>
> On Mon, Jul 18, 2016 at 3:42 PM, Alan Ezust <alan.ezust at gmail.com> wrote:
>
>> modelData is indeed a special reserved data role for use inside delegates
>> with certain kinds of models, including C++ objectlists and also
>> stringlistmodel.
>>
>> I can't find any documentation that explains exactly what 'modelData' is
>> or where it is "reserved".
>>
>> However, modelData mentioned here:
>> http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html
>>
>> And mentioned again here:
>> http://doc.qt.io/qt-5/qml-qtquick-repeater.html
>>
>> Cheers --Alan
>>
>>
>>
>> On Thu, Jul 14, 2016 at 10:07 PM, Kevin Mcintyre <kebin70 at gmail.com>
>> wrote:
>>
>>> Below is psuedo code...am I doing something wrong - or is modelData
>>> reserved?
>>>
>>> //This works.
>>> -- ~repeater.qml
>>> Item {
>>>     Repeater {
>>>         model: [
>>>             ["example"],
>>>         ]
>>>         delegate: Qt.createComponent("maybe_delegate.qml")
>>>     }
>>> }
>>>
>>> -- maybe_delegate.qml
>>> Item {
>>>     objectName: modelData[0]
>>> }
>>>
>>> //This does not?
>>> -- nondelegate.qml
>>> Item {
>>>     id: nondelegate
>>>     Component.onCompleted: {
>>>
>>> Qt.createComponent("maybe_delegate.qml").createObject(nondelegate,{
>>> modelData: ["example1"]});
>>>     }
>>> }
>>>
>>> _______________________________________________
>>> 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/20160719/9ed960d1/attachment.html>


More information about the Interest mailing list