Sharing information related to Qt, Maemo development and some other information

Saturday, August 10, 2013

Using VibrationController API wit BB10 Cascades QML

I tried to add vibration support to my BB10 application Counter. Application is simple, which just increment the count when you press add button and decrements count on minus button. Simple but useful, I use it quite often to count the stuffs.

But you need to see at screen to see if it button is really pressed, so I thought to add vibration support, so I know button is pressed even without looking at screen. This is first time I am adding Vibration support to any of BB10 application. So I thought to share code.

Code is much simple, only trick is that you need to register VibrationController c++ class to QML system.

Here is how it goes.

First we need to link device lib which has VibrationController API. Add following line to your .pro file and you are good to go.

LIBS += -lbbdevice

Now in main.cpp you need to add proper header to locate VibrarionController API and the register it to QML registry.

Now we are ready to use VibrarionController with QML code. First you need to import VibraionController QML by import statement. Then we are creating it by defining it in attachedObjects. Once this is done, we can use it's start API to vibrate phone with certain intensity for certain durarion.