Script - writeConfig with QVariant

El boulangero elboulangero at gmail.com
Thu Mar 14 23:10:01 UTC 2013


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


2013/3/14 El boulangero <elboulangero at gmail.com>:
> Hi Matěj,
>
> thanks for your reply.
>
> I dug a little bit into the direction you pointed, but I'm not gonna
> continue. Too difficult, sorry.
>
> What I did is that I added a dummy argument to the function:
>>    - void writeConfig( String name, QVariant content )
> which became:
>>    - void writeConfig( String name, QVariant content, int dummy )
>
> With this I'm sure to pass into the right function. Then, I call it
> from my javascript:
>> var conf = { "test": "testing" };
>> Amarok.Script.writeConfig("heho", conf, 0);
>
> Then, in the amarok conf file, I have the "heho" variable, but the
> value is empty !
>
> 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"
>
> At this point I decided to stop, because I feel like I'm just trying
> random things.
>
> Thanks anyway for your reply,
>
> Regards,
> Arnaud
>
>
> 2013/3/14 Matěj Laitl <matej at laitl.cz>:
>> On 13. 3. 2013 El boulangero wrote:
>>> Hello everyone,
>>
>> Hi!
>>
>>> I writing a scritp for Amarok at the moment, and I have a question
>>> regarding the Amarok.Script API.
>>>
>>> I understand perfectly the config function with string argument, ie:
>>>    - String readConfig( String name, String defaultValue )
>>>    - void writeConfig( String name, String content )
>>>
>>> But I'm curious about the two other ones, with QVariant argument:
>>>    - QVariant readConfig( String name, QVariant defaultValue )
>>>    - void writeConfig( String name, QVariant content )
>>>
>>> At first, I thought that with these functions, I could put my script config
>>> in a JSON object, and save it in one call.
>>>
>>> For example:
>>> > var defconfig = {
>>> >     "time": {
>>> >         "monday": {
>>> >             "enabled": "true",
>>> >             "value": "08:00:00"
>>> >         }
>>> >     }
>>> > };
>>> >
>>> > Amarok.Script.writeConfig("", defconfig);
>>>
>>> But if I try that, I get the following error:
>>> > Script error reported by: Good Morning TypeError: ambiguous call of
>>> > overloaded function writeConfig(); candidates were
>>> > writeConfig(QString,QVariant) writeConfig(QString,QString)
>>>
>>> Is there something else I should do in order to use these functions? Or
>>> maybe I'm completely wrong, these functions are not suppose to be used with
>>> JSON objects?
>>
>> First, bad news: QtScript bindings of Amarok are in rather unmaintained state.
>> :-(
>>
>> Good news: you can fix them! :-)
>>
>> To answer your question: Your code is much probably right, but the Amarok part
>> may have never worked, you've just first to shout loudly. To quote from [1]:
>>> Like other C++ methods, meta-methods can be overloaded, and they can have
>>> default arguments. The QtScript binding tries to ensure that the intended
>>> overload is called. First, if there is an overload that expects precisely
>>> as many arguments as were passed, that overload is selected. Second, if
>>> there's more than one such overload, the decision is based on a heuristic
>>> of how well the source (JS) argument types match with the target (C++)
>>> argument types. If the heuristic doesn't help either, a TypeError is
>>> thrown.
>>
>> The error you have seems to happen in the Javascript wrapper of
>> AmarokScriptConfig class. What I suggest is that you rename QVariant variant of
>> the writeConfig in src/scriptengine/AmarokScriptConfig.{h,cpp} method and see if
>> it fixes your problem.
>>
>> You might encounter another problem that KConfigGroup::writeEntry( QString,
>> QVariant ) doesn't support complex QVariants (those with containers in them),
>> please consult its documentation and implementation.
>>
>> [1] http://trac.webkit.org/wiki/QtScript (probably best C++ <-> QtScript
>> interaction documentation, better than official Qt doc)
>>
>> Regards,
>>                 Matěj



More information about the Amarok mailing list