Sunday, June 19, 2011

QtQuick - From Bling Bling To Blink Blink

Probably most of you already know that QtQuick is used to create amazing blingalicous UIs without too much effort. The declarative QML language makes it very easy to create object instances and setup property bindings, animation, states etc. Lately I’ve been tinkering with my Velleman K8055 USB experiment board and wanted to create a nice UI to control the board. It didn’t take too long until I was thinking a little bit out side of the box and started experimenting with controlling the board with QtQuick but without a UI. I created a couple of QML components on the C++ side to control the input/outputs of the board and quickly realized the possibilities QML provides even for non-UI applications.

Basically what I did was to create a declarative engine and not a declarative view. By doing this you can have a QML file interpreted and access to the object instances created by the engine from within your C++ code. I see a lot of potential and possibilities, one thing that comes to my mind straight away is to utilize QML as a Dependency Injection container :)
QDeclarativeEngine *engine = new QDeclarativeEngine;
QDeclarativeComponent component(engine, QUrl("qrc:/example1.qml"));
Board *board = qobject_cast<board *>(component.create());
Example code to interpret a QML file
The source code is available at k8055tinker

Check out the video below which demonstrates my code:


I've also tagged this post with Python because it can be of interest for the planet python readers since this can also be accomplished with PySide.

2 comments:

  1. That is pretty neat. Gave me some ideas too actually. Didn't even think of Python + Arduino combination. With QML it might even be more more interesting.

    Here are some related projects
    http://thp.io/2010/psmove/
    http://www.developer.nokia.com/Community/Wiki/index.php/Communicating_with_Arduino

    ReplyDelete
  2. The psmove thingy looks cool, unfortunately I don't have one

    I actually got an Arduino recently and also though of re-writing this demo for that board but didn't find the time :(

    Please keep me updated if you do anything fun!

    ReplyDelete