Category Archives: Programming

Home / Programming
3 Posts

Sometimes you want to transfer an url or very complicated password to you mobile phone. For example:

qrapp (speak “crap” 😉 ) does exactly that. It sits there readily in your traybar, as soon as you click on the icon it will automagically read the contents of you clipboard and generate a QR code.

Draw your mobile phone and launch your favorite QR reader – voila. Most QR readers will detect an URL and offer you to open it in the browser. qrcode-img qrapp is free software. Get it here: Download for MacOSX Yosemite Happy hacking!

I have struggled a lot to simply obtain a continous video stream from QCamera without QtGui as single QImages. After a lot of searching, I finally got to a very short and elegant solution. The Qt documentation is really lacking about this. The obvious (and imo correct) solution would be to use QVideoProbe and connect to the videoFrameProbed signal, but this does only work on a couple of platforms and in very exotic constellations (for example, as of now QCamera only works with with QVideoProbe on Android).

The solution is to subclass QAbstractVideoSurface and override its present-method. This is how it looks like:

#include "cameraframegrabber.h"

CameraFrameGrabber::CameraFrameGrabber(QObject *parent) :

QList<QVideoFrame::PixelFormat> CameraFrameGrabber::supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
    return QList<QVideoFrame::PixelFormat>()
        << QVideoFrame::Format_ARGB32
        << QVideoFrame::Format_ARGB32_Premultiplied
        << QVideoFrame::Format_RGB32
        << QVideoFrame::Format_RGB24
        << QVideoFrame::Format_RGB565
        << QVideoFrame::Format_RGB555
        << QVideoFrame::Format_ARGB8565_Premultiplied
        << QVideoFrame::Format_BGRA32
        << QVideoFrame::Format_BGRA32_Premultiplied
        << QVideoFrame::Format_BGR32
        << QVideoFrame::Format_BGR24
        << QVideoFrame::Format_BGR565
        << QVideoFrame::Format_BGR555
        << QVideoFrame::Format_BGRA5658_Premultiplied
        << QVideoFrame::Format_AYUV444
        << QVideoFrame::Format_AYUV444_Premultiplied
        << QVideoFrame::Format_YUV444
        << QVideoFrame::Format_YUV420P
        << QVideoFrame::Format_YV12
        << QVideoFrame::Format_UYVY
        << QVideoFrame::Format_YUYV
        << QVideoFrame::Format_NV12
        << QVideoFrame::Format_NV21
        << QVideoFrame::Format_IMC1
        << QVideoFrame::Format_IMC2
        << QVideoFrame::Format_IMC3
        << QVideoFrame::Format_IMC4
        << QVideoFrame::Format_Y8
        << QVideoFrame::Format_Y16
        << QVideoFrame::Format_Jpeg
        << QVideoFrame::Format_CameraRaw
        << QVideoFrame::Format_AdobeDng;

bool CameraFrameGrabber::present(const QVideoFrame &frame)
    if (frame.isValid()) {
        QVideoFrame cloneFrame(frame);;
        const QImage image(cloneFrame.bits(),
                           QVideoFrame::imageFormatFromPixelFormat(cloneFrame .pixelFormat()));
        emit frameAvailable(image);
        return true;
    return false;

// Qt includes
#include <QAbstractVideoSurface>
#include <QList>

class CameraFrameGrabber : public QAbstractVideoSurface
    explicit CameraFrameGrabber(QObject *parent = 0);

    QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const;

    bool present(const QVideoFrame &frame);

    void frameAvailable(QImage frame);

public slots:



This is how you would use it in your Qt application:

_camera = new QCamera();
_cameraFrameGrabber = new CameraFrameGrabber();
connect(_cameraFrameGrabber, SIGNAL(frameAvailable(QImage)), this, SLOT(handleFrame(QImage)));

You can download both files here:

Within this blogpost, I’d like to write about QJackAudio, which is actually the result of a personal itch I scratched. I know that others had the same problem as we had, since there have been libraries developed such as QJack, which are abandonend now. But first things first, let me explain what JACK is and why you might need a library like QJackAudio.

JACK is a low-latency sound server that runs on top of the the operating system’s sound architecture. Actually, this is not a new idea, a lot of professional audio software manufacturers introduced such a system in order to make it possible to route audio signals in near-realtime. A practical use-case would be recording audio and being able to monitor your recording via software without a significant delay in your playing and the monitored signal. JACK has evolved to what one might call a standard in the professional GNU/Linux audio world. Practically all DAWs, effects processors and analysis software running on GNU/Linux support JACK.

Due to the fact that all software is able to communicate with the JACK audio server, you can connect any application to another using virtual cables, for example with qjackctl, which is a control application for the JACK server and allows you to draw connections (audio and MIDI) visually. If you launch an application and that application registers at the JACK server, qjackctl will display that unit and all its in- and outputs that you can drag on those of other JACK applications.

Applications that want to use JACK can use libjack, a C-library that you can link against (it’s LGPL). I you are aiming for clean code, you will most probably wrap that C code in C++/Qt classes – and that is where QJackAudio kicks in. I have done that once, and rewritten everything a second time to provide a wrapper in a library that you can make use of. As a plus, I have included a few common digital filters that are common in the audio world, such an EQ, an amplifier, compressor and the the list goes on (and there is more to come). Just create a new project and write your own effects, virtual guitar amps, mixers or anything you might think of, without worrying about hardcore DSP stuff.

In order to demonstrate its capabilities, I have written a demo application called mx2482 that is build on top of QJackAudio. The project is hosted on github, for more information see here: