<div dir="ltr">Hi,<div><br></div><div>I just noticed something unusual with assigning delegates to data models in QML. I have following item to use as a delegate:</div><div><br></div><div><font class="Apple-style-span" face="georgia, serif">Item {</font></div>
<div><font class="Apple-style-span" face="georgia, serif"> id: delegateItem</font></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><font class="Apple-style-span" face="georgia, serif"> Text { text: modelData }</font></div>
<div><font class="Apple-style-span" face="georgia, serif">}</font></div><div><br></div><div>And following data model:</div><div><br></div><div><font class="Apple-style-span" face="georgia, serif">Row {</font></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><font class="Apple-style-span" face="georgia, serif"> Repeater {</font></div>
<div><meta http-equiv="content-type" content="text/html; charset=utf-8"><font class="Apple-style-span" face="georgia, serif"> model: ["hello", "world"]</font></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><font class="Apple-style-span" face="georgia, serif"> delegate: delegateItem</font></div>
<div><meta http-equiv="content-type" content="text/html; charset=utf-8"><font class="Apple-style-span" face="georgia, serif"> }</font></div><div><font class="Apple-style-span" face="georgia, serif">}</font></div><div><br>
</div><div>Such a usage throws the error: Unable to assign QObject* to QDeclarativeComponent*</div><div>If I change the delegateItem from Item{} to Component{}, it says: QML Component: Delegate component must be Item type.</div>
<div><br></div><div>However, if I use it as follows, it works:</div><div><br></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div><font class="Apple-style-span" face="georgia, serif">Row {</font></div>
<div><font class="Apple-style-span" face="georgia, serif"> Repeater {</font></div><div><font class="Apple-style-span" face="georgia, serif"> model: ["hello", "world"]</font></div><div><font class="Apple-style-span" face="georgia, serif"> delegate: Item {</font></div>
<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><font class="Apple-style-span" face="georgia, serif"> id: delegateItem</font></div><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>
<font class="Apple-style-span" face="georgia, serif"> Text { text: modelData }</font></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><font class="Apple-style-span" face="georgia, serif"> }</font></div>
<meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"><div><font class="Apple-style-span" face="georgia, serif">}</font></div>
<div><br></div></div><div>But this makes the code look really messed up. Any alternatives?</div><div><br></div><div>Viranch</div><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"></div>