Important: Please read the Qt Code of Conduct -

Qt Mobility on PlayBook

  • I've been trying to get the sensor stuff with the Qt Mobility working for the PlayBook with the NDK 2,1. I'm using Qt version 4.8.3 which is the official version supported for the PlayBook. All the GUI and core Qt stuff works fine. When I try getting sensor data using Qt Mobility, I get the following error:

    @QFactoryLoader::QFactoryLoader() looking at "/apps/com.example.QTPlaybook.testDev__QTPlaybookc87a03f1/native/lib/platforms/"
    keys ("blackberry")
    QFile::setFileName: File (/dev/sensor/accel) is already opened
    Starting sensor "/dev/sensor/accel" failed: "Unknown error"
    Starting sensor "/dev/sensor/accel" failed: "Unknown error" @

    I tried getting the accelerometer data using both QML and C++ methods and both results in the same error. As soon as I call start() on the QAccelerometer object, it gives me the error. I know the sensor plugin is added and can be referenced. I also know I can get the accelerometer data using native calls using the NDK so I know the sensor is functional.

    Can anyone tell me what I'm missing? any help is greatly appreciated

  • Alright I resolved the above problem by ignoring the instructions on
    to use and compile git:// instead. Maybe someone with access can update the wiki?

    Now I can get the accelerometer data using QML. with no issues. But if I try getting it in C++ I get a segfault. The code I'm running is sample code:
    @#include <QtCore>
    #include <QAccelerometer>


    QAccelerometer *accelerometer;

    class AccelerometerFilter : public QAccelerometerFilter
    bool filter(QAccelerometerReading *reading)
    qDebug() << "acceleration: "
    << QString().sprintf("%0.2f %0.2f %0.2f",
    return false; // don't store the reading in the sensor

    int main(int argc, char **argv)
    QCoreApplication app(argc, argv);

    QAccelerometer sensor;
    accelerometer = &sensor;
    AccelerometerFilter filter;
    if (!sensor.isActive()) {
        qWarning("Accelerometer didn't start!");
        return 1;
    return app.exec();


    And here is the stack trace:
    @Thread [1] (Suspended : Signal : SIGSEGV:Segmentation fault)
    QtMobility::QOrientableSensorBase::setCurrentOrientation() at qorientablesensorbase.cpp:199 0x780f408c

    The code the segfault occurs in is
    @void QOrientableSensorBase::setCurrentOrientation(int currentOrientation)
    if (d->currentOrientation != currentOrientation) {
    d->currentOrientation = currentOrientation;
    emit currentOrientationChanged(currentOrientation); //SEGFAULT HERE

    Could use some help how to prevent the segfault

  • OK. I found the issue. QAccelerometer can't be instantiated locally. It needs to be passed in a QObject pointer in its constructor. No more seg faults. The sensor readings are still however all 0's. The following is outputted to the console continuously:
    @acceleration: "0.00 0.00 0.00" @

    If I use QML method I get the correct values. So it must be something I'm doing wrong.

    Here is the QML way that works:
    @import QtQuick 1.1
    import QtMobility.sensors 1.2
    Rectangle {
    id: root
    color: "blue"
    Accelerometer {
    active: true
    onReadingChanged: {
    console.log("New reading: " + reading.x + "," + reading.y + "," + reading.z)

Log in to reply