Plasma 2 DataEngine & QML bindings

Mark markg85 at gmail.com
Wed Jul 3 09:41:20 UTC 2013


On Tue, Jul 2, 2013 at 3:18 AM, Sebastian Kügler <sebas at kde.org> wrote:
> Hi,
>
> I'm looking into our dataengine and relevant QML bindings right now, I can now
> load a dataengine and use it from Plasma 2, but I have to convert the payload
> (::data() from a QHash to a QVariantMap.
>
> In src/declarativeimports/core/datasource.*) the data property returns
> QHash<QString, QVariant>. This doesn't seem to be consumable from QML,
> (javascript code sees a  QVariant(QVariantHash), but I can't iterate over it,
> it has no keys, no [] accessors, etc..
> Converting it to a QVariantMap instead makes it work from QML, but it's not
> actually what we want to do here. Or is it?
>
> There's some qscriptvalue magic that I don't understand completely in
> dataenginebindings_p.h, is this the necessary glue to do the conversion
> automatically (and more efficiently)?
>
> Cheers,
> --
> sebas
>

Hi Sebas,

Just a quick thought. Does it help if you expose the data as a
QAbstractItemModel (or QAbstractListModel)? That way you stay in
control of how the data is represented in the backend without
conversions specifically for QML. It also makes it very easy to use
the data in QML views :)

The downside is probably that you need to have a model class which can
be a big pain to make (specially QAbstractItemModel).

Cheers,
Mark


More information about the Plasma-devel mailing list