Pong

July 24th 2015, QCompass

July 21th 2015 SourceForge Down Time | | July 26th 2015 Compass Smoothing

Q How do we measure the azimuth of the built-in compass of smart phones with Qt?

We implement the filter method of the QCompassFilter class, like so:

class CompassInfo: public QObject, public QCompassFilter
{
   Q_OBJECT

public:

   CompassInfo(QObject* parent = NULL)
      : QObject(parent)
   {
      m_sensor = new QCompass(this);
      m_sensor->addFilter(this);
      m_sensor->start();
   }

private slots:

   virtual bool filter(QCompassReading *reading)
   {
      qreal a = reading->azimuth();

      emit azimuth(a);

      return(true);
   }

private:

   QCompass* m_sensor;

signals:

   void azimuth(qreal a);
};

If we instantiate the above class and connect a slot to its azimuth signal, we will receive all compass updates in the connected slot:

CompassInfo *info = new CompassInfo;
connect(info, SIGNAL(azimuth(qreal)), this, SLOT(azimuth(qreal)));


July 21th 2015 SourceForge Down Time | | July 26th 2015 Compass Smoothing

Options: