Tuesday, November 6, 2012

Quickie - QtCore.js proof-of-concept

Wow - long time, no blog. I've recently being doing some work on Kate's Vim mode and should really be continuing to work on that (I'll blog about it when I have something more substantial to report), but got side-tracked when I heard about the remarkable Emscripten project, and starting pondering whether I could get Qt to work on it.

For the uninitiated - Emscripten leverages the awesome LLVM and clang projects to take code compiled using clang - usually C/C++, but presumably any language which clang can compile and for which there is an Emscripten-ified library/ runtime available - and converts it into Javascript. After about 15 hours of work, I finally have Qt4 QtCore Emscripten-ified sufficiently well to print a simple, QString-based "Hello, world!". Warning: This is a big (13MB!) webpage, which will require a decent amount of RAM:

Hello, QtCore.js!

The original C++ source is the trivially simple one from here.

It doesn't seem to work in Konqueror/ Rekonq at the moment, but then, very few of the official demos work there, either. I haven't looked into why, yet.

There's a lot left to do - obviously, one of the major issues is that I haven't even looked at QtGui yet, and I haven't implemented the QtCore.js approximation of the event loop - but it should be a fun mini-project :) I'm not sure how far I'll take it, though - the resulting Javascript is impractically huge (although currently I don't think I'm applying any of Emscriptens - or maybe even llvm's - optimisations, yet) and that's just for QtCore. Plus, there are some limitations that are the result of using Javascript - no QThread support, for a start (and HTML5's web workers offer no help, here) and also it will almost certainly be impossible to have local event loops, meaning that any app that uses the *::exec methods for their pop up menus, message boxes, network activity etc will have to be re-worked to use the asyncronous versions instead.

If anyone's interested, I'm blog again in a few days time, if I've made any progress. If any Trolls want to give me some hints on how to get QtGui + plus a simple window system up-and-running using HTML5 Canvases, that would be hugely appreciated :)

Quick update: I turned the optimisations on, and it shrunk to a much more reasonable 1.8MB :)

No comments: