Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QCompass in QT Quick mobile App

QCompass in QT Quick mobile App

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 2 Posters 786 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.
  • P Offline
    P Offline
    Phips04
    wrote on 6 Nov 2020, 17:58 last edited by
    #1

    Hi everyone,
    I'm actually creating an mobile application for my android tablet in QT Quick.
    The application now needs to read data from the QCompass sensor.
    I tried this:

    Header file - backend.h:
    Qt_h.jpg

    Code file - backend.cpp:
    Qt_cpp.jpg

    Image and Backend implementation:
    Qt_qml1.jpg

    Timer implementation:
    Qt_qml2.jpg

    My goal is to assign the heading retrieved via "backend.NumericHeading" to the rotation property of the image.
    Every time I run this, android terminates my app, and tells that the app was paused for some reason (no details).
    Thanks for your help.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Phips04
      wrote on 7 Nov 2020, 21:21 last edited by
      #2

      I tried this now, it runs fine, but checkValue is never triggered.

      Backend::Backend(QObject *parent) : QObject(parent)
      {
      compass = new QCompass(this);

      connect(compass, SIGNAL(readingChanged()), this, SLOT(checkReading()));
      
      compass->start();
      
      Value = 45;
      

      }

      void Backend::checkReading()
      {
      Value = 180;
      }

      J 1 Reply Last reply 9 Nov 2020, 06:04
      0
      • P Phips04
        7 Nov 2020, 21:21

        I tried this now, it runs fine, but checkValue is never triggered.

        Backend::Backend(QObject *parent) : QObject(parent)
        {
        compass = new QCompass(this);

        connect(compass, SIGNAL(readingChanged()), this, SLOT(checkReading()));
        
        compass->start();
        
        Value = 45;
        

        }

        void Backend::checkReading()
        {
        Value = 180;
        }

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 9 Nov 2020, 06:04 last edited by
        #3

        @Phips04 said in QCompass in QT Quick mobile App:

        connect(compass, SIGNAL(readingChanged()), this, SLOT(checkReading()));

        You should use new connect syntax:

        connect(compass, &QCompass::readingChanged, this, &Backend::checkReading);
        

        You should also connect a slot to https://doc.qt.io/qt-5/qsensor.html#sensorError and check whether you get any errors.
        And I think your app has to request access rights to read from the sensors.

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

        1 Reply Last reply
        2
        • P Offline
          P Offline
          Phips04
          wrote on 10 Nov 2020, 11:40 last edited by
          #4

          @jsulm Just tried the new syntax, the app runs without interruptions but checkReading is never entered.
          I registerd a slot for sensorError, the affected function is never called to.
          Since the QMagnetometer sensor doesn't work to I think the reason for this problem could be the access rights. I checked the list of permissions in the AndroidMainfest.xml file, but I didn't find any entry which I think could match this.
          Do you know one?

          NavSysPermissions.jpg

          J 1 Reply Last reply 10 Nov 2020, 11:53
          0
          • P Phips04
            10 Nov 2020, 11:40

            @jsulm Just tried the new syntax, the app runs without interruptions but checkReading is never entered.
            I registerd a slot for sensorError, the affected function is never called to.
            Since the QMagnetometer sensor doesn't work to I think the reason for this problem could be the access rights. I checked the list of permissions in the AndroidMainfest.xml file, but I didn't find any entry which I think could match this.
            Do you know one?

            NavSysPermissions.jpg

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 10 Nov 2020, 11:53 last edited by
            #5

            @Phips04 said in QCompass in QT Quick mobile App:

            Do you know one?

            Check https://stackoverflow.com/questions/20497087/manifest-xml-when-using-sensors
            and https://developer.android.com/guide/topics/sensors/sensors_position

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

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Phips04
              wrote on 10 Nov 2020, 16:24 last edited by
              #6

              I added the <uses-permission/> statements to my AndroidManifest.xml file, but the testing's outcomes stayed the same.

              @jsulm said in QCompass in QT Quick mobile App:

              https://developer.android.com/guide/topics/sensors/sensors_position

              The android NDK seems to offer a SensorManager class. Is it necessary in Qt to use QSensorManager?. I didn't figure out the way of how to use it yet.

              J 1 Reply Last reply 11 Nov 2020, 05:35
              0
              • P Phips04
                10 Nov 2020, 16:24

                I added the <uses-permission/> statements to my AndroidManifest.xml file, but the testing's outcomes stayed the same.

                @jsulm said in QCompass in QT Quick mobile App:

                https://developer.android.com/guide/topics/sensors/sensors_position

                The android NDK seems to offer a SensorManager class. Is it necessary in Qt to use QSensorManager?. I didn't figure out the way of how to use it yet.

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 11 Nov 2020, 05:35 last edited by
                #7

                @Phips04 said in QCompass in QT Quick mobile App:

                Is it necessary in Qt to use QSensorManager?

                Should not, but I'm not expert in this area.

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

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  Phips04
                  wrote on 11 Nov 2020, 18:08 last edited by
                  #8

                  Deploying this code on Windows doesn't change the situation, just checked this out.

                  1 Reply Last reply
                  0

                  4/8

                  10 Nov 2020, 11:40

                  • Login

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