Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. What is wrong with QCompass?
Forum Updated to NodeBB v4.3 + New Features

What is wrong with QCompass?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
7 Posts 2 Posters 538 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gourmet
    wrote on last edited by Gourmet
    #1

    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(5); // 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();
    }
    

    Data are requested periodically 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
    (null):0 ((null)): device azimuth 0
    (null):0 ((null)): device azimuth 0
    (null):0 ((null)): device azimuth 0
    (null):0 ((null)): device azimuth 0
    (null):0 ((null)): device azimuth 0
    

    in any device position.

    I am pretty sure other compass simulating applications work fine on this device.
    Result is the same with any

    compass->setDataRate(5); // 100, 500, 0... doesn't matter
    

    What I did wrong or what I did not?

    jsulmJ 1 Reply Last reply
    0
    • G Gourmet

      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(5); // 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();
      }
      

      Data are requested periodically 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
      (null):0 ((null)): device azimuth 0
      (null):0 ((null)): device azimuth 0
      (null):0 ((null)): device azimuth 0
      (null):0 ((null)): device azimuth 0
      (null):0 ((null)): device azimuth 0
      

      in any device position.

      I am pretty sure other compass simulating applications work fine on this device.
      Result is the same with any

      compass->setDataRate(5); // 100, 500, 0... doesn't matter
      

      What I did wrong or what I did not?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @gourmet said in What is wrong with QCompass?:

      compass->stop();

      Why do you stop the sensor in your slot?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      G 1 Reply Last reply
      0
      • jsulmJ jsulm

        @gourmet said in What is wrong with QCompass?:

        compass->stop();

        Why do you stop the sensor in your slot?

        G Offline
        G Offline
        Gourmet
        wrote on last edited by
        #3

        @jsulm to not waste processor time when it is not neeed. It starts periodically from other thread.This does not affect the result - sensor sends "ready" data but they are zero. Why?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Gourmet
          wrote on last edited by
          #4

          Wow! Things are more strange than I can imagine. Today I started work with this app - and suddenly have got proper azimuth values. Once. Next time when I run app - value become 0 again.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Gourmet
            wrote on last edited by
            #5

            If I do not stop compass - it works. But it wastes resources cause it is not needed all the time. Once I stop compass when it is not needed - next app run it doesn't work. Looks like a bug.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Gourmet
              wrote on last edited by
              #6

              Looks like I find workaround this. First I start compass in constructor of class using it. Then I stop compass little later. Next time I start it again when need azimuth and stop when get it. This way works - I get azimuth values in all program runs. But this is definitely a bug in QCompass.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                Gourmet
                wrote on last edited by
                #7

                Bug report.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved