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 992 Views 1 Watching
  • 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 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 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;
      }

      jsulmJ 1 Reply Last reply
      0
      • P Phips04

        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;
        }

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on 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 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

          jsulmJ 1 Reply Last reply
          0
          • P Phips04

            @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

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on 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 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.

              jsulmJ 1 Reply Last reply
              0
              • P Phips04

                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.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on 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 last edited by
                  #8

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

                  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