Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 53
Registered: ‎09-19-2012
My Device: 9700
My Carrier: China mobile

ProximitySensor never get any reading

The toss game sample can't build in beta3

I built the codes as:

 

/*
 * ProximitySensor.h
 */

#ifndef PROXIMITYSENSOR_H_
#define PROXIMITYSENSOR_H_
#include <QObject>
#include <QtSensors/QProximitySensor>
#include <QtSensors/QProximityFilter>
#include <QtSensors/QProximityReading>
#include <bb/cascades/Application>
using namespace QtMobility;
class ProximitySensor: public QObject, public QProximityFilter { //
Q_OBJECT
 ;Q_PROPERTY(bool isClose READ isClose NOTIFY proximityChanged)
 ;
public:
 ProximitySensor();
 ProximitySensor(QObject *parent);
 virtual ~ProximitySensor();
 bool isClose() const;
 void start();
 void stop();
 Q_SIGNALS:
 void proximityChanged();
protected:
 bool filter(QProximityReading *reading);
private:
 QProximitySensor m_proximitySensor;
 bool m_isClose;
};

#endif /* PROXIMITYSENSOR_H_ */

 

/*
 * ProximitySensor.cpp
  */

#include "ProximitySensor.h"
#include <QDebug>
using namespace QtMobility;
ProximitySensor:Smiley TongueroximitySensor(QObject *parent) :
    QObject(parent), m_isClose(false){
    if (!m_proximitySensor.connectToBackend()) {
        qDebug() << "Cannot connect to proximity sensor backend!";
    }
 m_proximitySensor.addFilter(this);
}

ProximitySensor::~ProximitySensor() {
 // TODO Auto-generated destructor stub
}
bool ProximitySensor::isClose() const {
 return m_isClose;
}
void ProximitySensor::start(){
 m_proximitySensor.start();
}
void ProximitySensor::stop(){
 m_proximitySensor.stop();
}
bool ProximitySensor::filter(QProximityReading *reading) {
 m_isClose = reading->close();
 emit proximityChanged();
 return false;
}