Details
-
Bug
-
Resolution: Incomplete
-
P2: Important
-
None
-
5.9.6
-
None
Description
I need device azimuth for my Android application.
In Qt docs there is very few info about QSensors programming. Finding some examples from here and there I made some code. First I initialize compass:
QCompass* compass; ..... compass = new QCompass(this); compass->setDataRate(100); // Hz connect( compass, SIGNAL(readingChanged()), this, SLOT(gotCompassData()) ); qWarning()<<"********************** connecting to compass"<<compass->connectToBackend();
have got:
: (null):0 ((null)): ********************** connecting to compass true
Before I need azimuth call:
compass->start();
And catch signal to slot:
void MyClass::gotCompassData() { QCompassReading* reading = compass->reading(); if( reading != Q_NULLPTR ) qWarning()<<"device azimuth"<<reading->azimuth(); else qWarning()<<"nothing read"; compass->stop(); }
I need stop compass to not waste processor resources all the time. I want get azimuth only when I really need it - this is not permanent measuring. Data are requested periodically once per second but in console I see only this:
(null):0 ((null)): device azimuth 0
(null):0 ((null)): device azimuth 0
(null):0 ((null)): device azimuth 0
...
in any device position. Then I noticed - if I run any other application using compass then my app works fine after it. It shows proper azimuth values. But only in one run. On next run it gives 0s again. I supposed this is because of improper compass initialization or stopping. I removed compass->stop() call and placed compass->start() call to constructor of object using it. In this case application gets permanent azimuth values. But their frequency is very fast. This is not needed in my app. That means extra azimuth processing can slow down other application features. I found workaround this. First I call compass->start() in constructor then I call compass->stop() little later. When I need azimuth value I call compass->start() again and compass->stop() after I get the value. In this case application works and I can get azimuth only when I need it, not all the time.