Sunday, 18 September 2011

QtJs - Converting Qt c++ to JavaScript

I've approached this task from several angles.

by hand

QtJs is a SourceForge project I created to share some demos I made with JavaScript implementations of some of Nokias open source Qt's classes.

At the moment I've got a bare-bones JavaScript implementation on my web site, but I think I'm going to abandon it, as
  1. it takes ages
  2. every time Qt releases another version I'll have to manually update
  3. the Qt code base is huge
These are good reasons to try to develop a semi-automated approach.
When I say "semi-automated", I mean writing code that does a reasonable job most of the time, but handles corner cases using some kind of filter, be it location, name or scope, maybe a combination of these.
These corner cases will have an action to deal specifically with that case.

I can see this being applied first and foremost to the QObject / QWidget classes. Once I have them working, the rest should follow.

That said, the existing implementation has taken me a long way, and contains some useful ideas.

I had a new version in the works that chain-loads the seperate JavaScript files.
The main html file only has to reference "qtjs.js" and it gets the rest.
I'll definitely be using that approach until I wrap the whole thing up using the closure compiler.

I may also end up also using the closure library.

clang/llvm

I've had mixed success in my previous encounters with clang/llvm, which discouraged me from "biting the bullet" and committing to this semi-automated approach to the conversion.

emscripten

I had a look at emscripten and I may yet give it a go, if only to compare the two approaches.

Google chrome browser plugin

Google's NaCl promises to allow me to write JavaScript that runs in the (Google Chrome) web browser but uses a native Qt implementation.

Android plugin

There's an Android app called Ministro that allows you to run compiled Qt apps on your Android phone. I'll have to research if it's possible to leverage this from within an Android web browser though. It may be more trouble than it's worth given that you can just go ahead and write Android programs with Qt directly.

No comments:

Post a Comment