Assigning delegate to repeater model in QML

Viranch Mehta viranch.mehta at gmail.com
Fri Jun 17 19:33:08 CEST 2011


Hi,

I just noticed something unusual with assigning delegates to data models in
QML. I have following item to use as a delegate:

Item {
    id: delegateItem
    Text { text: modelData }
}

And following data model:

Row {
    Repeater {
        model: ["hello", "world"]
        delegate: delegateItem
    }
}

Such a usage throws the error: Unable to assign QObject* to
QDeclarativeComponent*
If I change the delegateItem from Item{} to Component{}, it says: QML
Component: Delegate component must be Item type.

However, if I use it as follows, it works:

Row {
    Repeater {
        model: ["hello", "world"]
        delegate: Item {
            id: delegateItem
            Text { text: modelData }
        }
}

But this makes the code look really messed up. Any alternatives?

Viranch
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/plasma-devel/attachments/20110617/830a81ec/attachment.htm 


More information about the Plasma-devel mailing list