Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to use QVibra to enable vibration in QML

From Wiki
Jump to: navigation, search

This article shows how to use QVibra, a Qt/QML wrapper API for vibration management on Symbian.

Article Metadata
Code Example
Source file: QVibra
Tested with
Devices(s): Nokia N8, Nokia C7-00
Compatibility
Platform(s): Symbian^1 and later, Qt 4.7 and later
Symbian
Article
Keywords: MHWRMVibraObserver,CHWRMVibra
Created: Sebastiano galazzo (05 Mar 2012)
Last edited: kiran10182 (15 Oct 2013)

Contents

Installation

  1. Download source code from here
  2. 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.

Applove.png

This page was last modified on 15 October 2013, at 18:35.
82 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×