First version of script with QJSEngine available

Pedro de Carvalho Gomes pedrogomes81 at gmail.com
Mon May 18 15:55:16 BST 2020


Hi all,

I have just pushed the first compiling version of the port from
QScriptEngine to QJSEngine. The branch is available at:

https://invent.kde.org/multimedia/amarok/-/tree/replace_Qtscript_with_QtQml

As I mentioned, it's the first compiling version. Still there are
several missing features, errors, etc. But it's a starting point if
anyone wants to see how I ported things. It was not trivial. Though
there's quite a big overlap between both scripting engines, still QJS*
misses _a lot_ of functionalities that are available at QTScript

For example, QScriptEngine::newFunction() exposes any method or
function to the engine. However QJEngine doesn't have such, and I
translated such calls to a combo of object import + referencing a
method as a JS property:
engine->newQObject(myobj)->property("myMethodName"); Additionally, I
had to encapsulate the engine pointer at the obj, sometimes by
creating a auxiliary class.

Another example was the registration of C++ types and its conversion
methods from/to script values. qScriptMetaTypeId<Type>( engine,
toScript, fromScript) is no longer avaiable. So I replaced it with the
combo qMetaTypeId<Type>() + registerConverter(toScript)
+registerConverter<QJSValue,T>(fromScript). Since the method
signatures where different, I wrapped toScript and fromScript with
lambda-functions.

As I said, this is the first *compiling* version. Few things are
working. Also, I haven't translated any of the built-in scripts (help
here is especially welcome). I plan to have a minimum-working version
soon. Then I plan to create Deb packages so people can provide
feedback.

Cheers,

Pedro


More information about the Amarok-devel mailing list