Wednesday, November 22, 2017

Qt for WebAssembly update

The project Qt 5 emscripten that Intopalo (who are doing tons of amazing stuff with some awesome talent) started as research for a client, has moved git repos. The new main git repo has been moved to a branch in Qt proper! and a new name - Qt for WebAssembly.

git://code.qt.io/qt/qtbase.git in the 'wip/webassembly' branch, and can be downloaded here:
git clone -b wip/webassembly git://code.qt.io/qt/qtbase.git

which is also here at github:
https://github.com/qt/qtbase/tree/wip/webassembly

Along with the move comes expanded requirements, like targeting non QtWidgets based apps, including QtDeclarative.

As well, it now builds only for wasm and does not bother with the asmjs fallback, This means your web browser will need to specifically support wasm. Pure wasm builds in emscripten have performance optimizations that do not happen when also building the asmjs fallback.

That said....

*NOTE* Qt for WebAssembly is still very alpha and buggy! Some of which I will cover in the next blog post.

I have managed to conjole Qt Creator to use the emscripten built Qt for apps. Here are the steps to do so, if you are so inclined.

Build Qt for web assembly.

1) Download and build emsdk (you may also try to pre built binary version)

git the emsdk source repo:
git clone https://github.com/juj/emsdk.git
(to update: git pull; ./emsdk update-tags )

Follow these instructions to build emsdk:
http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#installation-instructions

I usually use 'incoming' instead of 'latest', as it has more recent features.

/path/to/emsdk install sdk-master-64bit binaryen-master-64bit

2) Download Qt for emsdk

git clone -b wip/webassembly https://code.qt.io/qt/qtbase.git

3) Build Qt

source /path/to/emsdk/emsdk_env.sh

$QT_DIR/configure -xplatform emscripten -confirm-license -opensource -nomake tests -nomake examples -developer-build -no-dbus -no-headersclean -release -no-thread  -no-feature-networkinterface

(non developer builds should work too)

4) Add emscripten compiler to Creator

  • Tools->Options->Build & Run -> Compilers->Add->Custom
  • add emcc as C, and emc++ as C++
  • 'emscripten' as Qt mkspecs.
  • ABI: x86, linux (or whatever platform you build on), unknown, elf, 64bit

5) Add emscripten built Qt

  • Tools->Options->Build & Run ->Qt Versions->Add
    • add the qmake from your emscripten Qt build.
6) Add emscripten kit

  • Tools->Options->Build & Run ->Kits->Add
    • add emcc and emc++ as Compilers
    • If you use cmake, you can also add to CMake configuration:
      • CMAKE_TOOLCHAIN_FILE=/path/to/emsdk/emscripten/incoming/cmake/Modules/Platform/Emscripten.cmake
7) Build your app
  • Use 'release' mode build, as 'debug' will result in a runtime error: "failed to asynchronously prepare wasm: CompileError: wasm validation error: at offset 14762: too many functions"
8) Run your app

  • add custom executable: Projects->(qt5-wasm) Run
    • specify /path/to/emsdk/emscripten/incoming/emrun
      • arguments: .html
        • I also use --browser firefox (I use nightly)
Hopefully some things will actually work! This is all still in the development phase. Your kilometerage will vary. 

Good luck! You can join the fun, we are in #qt-webassembly at https://qtmob.slack.com and on freenode.


Monday, June 5, 2017

Qt for web (assembly)

So ya, I have been doing work for the up and coming Finnish company Intopalo getting Qt5 for WebAssembly using emscripten up and running. This is the 3rd Finnish company I have done work for, and the 4th Nordic company (Trolltech, Nokia, Jolla, Intopalo)

This is very much a work in progress.

Background:

There was a Qt4 version, emscripten-qt and a related Qt5 for Native Client which do similar things, and we have taken inspiration from both these projects. Thanks!

The gist of it:

We use emscripten to cross compile Qt5 into javascript and/or webassembly. We use 'incoming' from emscripten's git repo. Details how to build emsdk are here.

My working Qt5 repo is here, (the wm branch contains multi window and window decorations) while there is also an outdated WIP gerrit MR  which will get updated at some point.

This is how I configure Qt for emscripten:
 . ~/emsdk/emsdk_env.sh (to get em compiler in path)

~/depot/qt/qt5/qtbase/configure -xplatform emscripten -confirm-license -opensource -nomake tests  -nomake examples -developer-build -no-dbus -no-thread

 (no-thread is a new feature I added for this, as threading in javascript is basically non existent)

and then, use that qmake to compile a Qt app!

To run the app, in the firefox browser
emrun --browser firefox path/to/app.html

This is all bleeding edge from the emscripten compiler to the web assembly support in the browser, so your mileage may vary.

With the 'wm' branch of my github repo, multi windows and window decorations are kind of working. As well as compiling into webassembly and not just javascript asmjs.
Compiling into wasm brings much smaller download sizes, but you need to have a browser that supports it.

There is still heaps of work to do to bring it up to release state. So for now, it is still a research and WIP project, and a lot of things may or may not work. But it can run some Qt widget based apps in your (firefox) browser!

The future:

Currently there is no support for qml/qt quick. That just means we haven't tried it as our focus is currently on widgets and opengl.

Personally, I would like to see location and some sensor events, but that is for the future.

Friday, May 5, 2017

new QtSensor IoT plugins!

I've said it before and I will say it again... one thing I am tired of hearing about, is that people think Qt is only for UI applications.
WRONG!
Qt is great for IoT as well! even without a UI. (IoT is today's buzzword for 'embedded', which really isn't embedded, just small) and you cannot have IoT without sensors!

I just submitted a MR to QtSensors to add support for the SenseHAT sensor board for raspberry pi:

https://codereview.qt-project.org/#/c/193456
For raspberry pi, you will need RTIMULib installed on your rpi (and dev package to compile QtSensors). It's in the default repo, so you don't actually need to compile RTIMULib yourself.

Even though this is submitted for dev branch and should be available in Qt Sensors 5.10, this will compile and work for the Qt 5.3 that comes with the raspbian distribution.

As well, if my spare time allows, I will also get my Matrix Creator QtSensor plugin into shape to submit as well.

I also have planned getting the TI SensorTag code I wrote shoved into a QtSensor plugin. What's special about the SensorTag is that it has (buzzword alert) wireless sensors! This is a bit more tricky as it will use and be dependent on Qt's QLowEnergyService but will work nonetheless. This plugin doesn't run on the device, but requires a host machine which has bluetooth.

Saturday, January 7, 2017

Movin' on...

A year has gone by since I started work with Canonical. As it turns out, I must be on my way. Where to? Not real sure at this moment, there seems plenty of companies using Qt & QML these days. \0/

But saying that, I am open to suggestions. LinkedIn
 
Plenty of IoT and devices using sensors around. Heck, even Moto Z phone has some great uses for sensor gestures similar to what I wrote for QtSensors while I was at Nokia.

But a lack of companies that allow freelance or remote work. The last few years I have worked remotely doing work for Jolla and Canonical. Both fantastic companies to work for, which really have it together for working remotely.

I am still surprised that only a handful of companies regularly allow remote work. I do not miss the stuffy non window opening offices and the long daily commute, which sometimes means riding a motorcycle through hail! (I do not suggest this for anyone)

Of course, I am still maintainer for QtSensors, QtSystemInfo for the Qt Project, and Sensor Framework for Mer, and always dreaming up new ways to use sensors. Still keeping tabs on QtNetwork bearer classes.

Although I had to send back the Canonical devices, I still have Ubuntu on my Nexus 4. I still have my Jolla phones and tablet.

That said, I still have this blog here, and besides spending my time looking for a new programming gig, I am (always) preparing to release a new album. http://llornkcor.com
and always willing to work with anyone needing music/audio/soundtrack work.