Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-77314

QCompass works wrong in Android

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Incomplete
    • Affects Version/s: 5.9.6
    • Fix Version/s: None
    • Component/s: Sensors
    • Labels:
      None
    • Platform/s:
      Android

      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.

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            gourmand64 Gourmet
            Reporter:
            gourmand64 Gourmet
            PM Owner:
            Veli-Pekka Heinonen Veli-Pekka Heinonen
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes