Script - writeConfig with QVariant
Matěj Laitl
matej at laitl.cz
Thu Mar 14 18:15:32 UTC 2013
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