Reply
Thread Tools
qwazix's Avatar
Moderator | Posts: 2,622 | Thanked: 5,447 times | Joined on Jan 2010
#1
I am trying to get data from QAccelerometer but I can't make it.

My code is like this. I just initialize an instance of this class from another, (pAccelerometer *a = new pAccelerometer(); ) but the filter method never runs.

Code:
#ifndef PACCELEROMETER_H
#define PACCELEROMETER_H
#include <QAccelerometer>

// Neccessary for Qt Mobility API usage
QTM_USE_NAMESPACE

class pAccelerometer : public QObject, public QAccelerometerFilter
{
    Q_OBJECT

public:

    pAccelerometer(QObject* parent = 0) : QObject(parent)
    {
        m_sensor = new QAccelerometer(this);
        m_sensor->addFilter(this);
        m_sensor->connectToBackend();
        m_sensor->setDataRate(100);
        m_sensor->start();
    }

private slots:

    // Override of QAcclerometerFilter::filter(QAccelerometerReading*)
    bool filter(QAccelerometerReading* reading)
    {
        qreal x = reading->x();
        qreal y = reading->y();
        qreal z = reading->z();

        // Process acceleration sensor readings ...

        qDebug("Current device acceleration: x=%f y=%f z=%f", x, y, z);
        return true;
    }

private:

    QAccelerometer* m_sensor;
};

#endif // PACCELEROMETER_H
The application outputs
Code:
Setting data rate 100 Hz (interval 10 ms) for "meego.accelerometer"
but then it goes silent

I can't use a signal to be notified when data changes as I am using the data runtime, and timing is important. In the documentation it says that filters are the way to go.

I also tried just creating a QAccelerometer instance and then get the readings in an "infinite" loop but it always returns 0.

Thanks
__________________
Proud coding competition 2012 winner: ρcam
My other apps: speedcrunch N9 N900 Jolla –– contactlaunch –– timenow

Nemo UX blog: Grog
My website: qwazix.com
My job: oob

Last edited by qwazix; 2012-11-18 at 17:28.
 
qwazix's Avatar
Moderator | Posts: 2,622 | Thanked: 5,447 times | Joined on Jan 2010
#2
I think I solved it. I had to move the instantiation of the pAccelerometer object in the constructor of the thread instead of in the run() function. Now it works.
__________________
Proud coding competition 2012 winner: ρcam
My other apps: speedcrunch N9 N900 Jolla –– contactlaunch –– timenow

Nemo UX blog: Grog
My website: qwazix.com
My job: oob
 

The Following User Says Thank You to qwazix For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 09:08.