How to use QVibra to enable vibration in QML
This article shows how to use QVibra, a Qt/QML wrapper API for vibration management on Symbian.
Article Metadata
Code Example
Source file: QVibra (Projects)
Tested with
Devices(s): Nokia N8, Nokia C7-00
Compatibility
Platform(s): Symbian^1 and later, Qt 4.7 and later
Article
Keywords: MHWRMVibraObserver,CHWRMVibra
Created: Sebastiano galazzo
(05 Mar 2012)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Installation
- Download source code from here
- Include QVibra directory into your project
.pro
symbian {
# Enables Vibra API
DEFINES += QVIBRA
contains(DEFINES, QVIBRA) {
include(./QVibra/vibra.pri)
}
}
main.cpp
#ifdef QVIBRA
#include <QtDeclarative>
#include "QVibra/qvibra.h"
#endif
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
#ifdef QVIBRA
qmlRegisterType<QVibra>("Vibra", 1, 0, "Vibra");
#endif
QmlApplicationViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
viewer.setMainQmlFile(QLatin1String("qml/QVibraSample/main.qml"));
viewer.showExpanded();
return app->exec();
}
QML
import QtQuick 1.1
import Vibra 1.0
Rectangle {
width: 360
height: 640
Column {
x:0
y:50
height: 300
width: 360
spacing: 20
Rectangle {
id:start
width: parent.width-50
height: 80
color:"gray"
Text {
text: qsTr("Start Vibra")
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log(vibra.start());
console.log("starting vibra")
}
}
}
Rectangle {
id:stop
width: parent.width-50
height: 80
color:"gray"
Text {
text: qsTr("Stop Vibra")
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
vibra.stop();
console.log("stopped vibra")
}
}
}
Rectangle {
id:vibra5
width: parent.width-50
height: 80
color:"gray"
Text {
text: qsTr("Vibra for 5 sec. medium intensity")
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
vibra.start(5000,50)
}
}
}
}
Vibra {
id:vibra
rotation : Vibra.Negative
onStatusChanged: {
switch(status) {
case Vibra.StatusOn: console.log("Vibra On"); break;
case Vibra.StatusOff: console.log("Vibra Off"); break;
default: console.log("Status unknown"); break;
}
}
}
}
The value range for intensity property is between 0 and 100.
Possible values for rotation property are:
- Positive ( the vibra motor rotates in the positive direction )
- Negative ( the vibra motor rotates in the negative direction )
When phone in connected to USB cable vibration does not work
Sample
Self-signed QVibraSample.sis can be downloaded for testing.
Featured Sample
- A real application AppLove can be downloaded.
- Shake your phone to discover a new romantic phrase. Your phone will vibrate.


Somnathbanik - Nice Concept
Hi Sebastiano,
I liked this concept and its really nice work. Although I tried to test the sample SIS file. When I run it I see three options "Start Vibra", "Stop Vibra" and "Vibra for 5 sec. medium intensity" . Now could you please walk me through the steps what should I perform to try the next step, cause when I click on those options seems to be nothing happens.
I am testing on Symbian Belle.somnathbanik 05:47, 13 March 2012 (EET)
Galazzo -
Hi Somnathbanik
I tested on Symbian Belle and worked.
I got the same issue ( but is not a real issue ) when I had my phone's settings setted on "no vibra".
Let me know if this help you. If you need more support here my skipe id: sebastiano.galazzo
Thanksgalazzo 10:37, 17 March 2012 (EET)
Galazzo - Added vibra motor rotation management
Thanks to Owen Zhao for cooperationgalazzo 18:14, 30 March 2012 (EEST)