Script - writeConfig with QVariant

El boulangero elboulangero at gmail.com
Wed Mar 20 22:29:06 UTC 2013


Hi,

> if you look at [1] you can see that there is no code path for
QVariant::Map.

thanks for the hint. I read that and also the KConfig tutorial [1], now I
understand better how it's supposed to work.

In the end I wrote a little serialize/deserialize function to automatically
read/write my JSON to the config file, it's very simple and it works great.

However, for each object (like QTime object or QList), I need to pass it to
Amarok.writeConfig() as a string, otherwise I get the error message
mentioned in my first mail:
> TypeError: ambiguous call of overloaded function writeConfig()

It's not a problem though, passing these objects as strings (with the JS
toString() function) gives the expected result.

Problem solved for me, thanks for the help !

Regards,
Arnaud

[1] http://techbase.kde.org/Development/Tutorials/KConfig

2013/3/17 Kevin Funk <krf at gmx.de>:
> On Friday 15 March 2013, 00:10, El boulangero wrote:
>
>> Hi again,
>
>>
>
>> > After that, I tried to hack in the writeConfig function, create a new
>
>> > QVariant with a simple string, and feed it to the
>
>> > KConfigGroup::writeEntry( QString, QVariant ) function.
>
>> >
>
>> > But then I got the following error from Amarok:
>
>> >> KConfigGroup::writeEntry: KConfigGroup::writeEntry - unhandled type
>
>> >> QVariantMap in group "Good Morning"
>
>> My bad, I messed up, I launched the wrong binary.
>
>> So, let me start again.
>
>>
>
>> If I hack the writeConfig, and do something like that:
>
>> > void AmarokScriptConfig::writeConfig( const QString &name, const
>
>> > QVariant &content, int dummy ) {
>
>> >
>
>> > QVariant v("yop");
>
>> > KGlobal::config()->group( m_name ).writeEntry( name, v );
>
>> >
>
>> > }
>
>>
>
>> It works just fine, I got the expected result.
>
>>
>
>> But if I let function as it is, ie:
>
>> > void AmarokScriptConfig::writeConfig( const QString &name, const
>
>> > QVariant &content, int dummy ) {
>
>> >
>
>> > KGlobal::config()->group( m_name ).writeEntry( name, content );
>
>> >
>
>> > }
>
>>
>
>> I get the error:
>
>> > KConfigGroup::writeEntry: KConfigGroup::writeEntry - unhandled type
>
>> > QVariantMap in group "Good Morning"
>
>> I guess it means my javascript object is converted to a QVariantMap by
>
>> the binding. And KConfigGroup::writeEntry is unabled to interpret
>
>> that.
>
>> Am I correct ?
>
>>
>
>> Regards
>
>
>
> I think so,
>
>
>
> if you look at [1] you can see that there is no code path for
QVariant::Map.
>
> Just restructure your config data so it can be properly (de)serialized.
> Lists are supported in KConfigGroup, so try to use them.
>
>
>
> Greets
>
>
>
> [1]
>
http://api.kde.org/4.10-api/kdelibs-apidocs/kdecore/html/kconfiggroup_8cpp_source.html
>
>
>
> --
>
> Kevin Funk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/amarok/attachments/20130320/7604b6f6/attachment.html>


More information about the Amarok mailing list