Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QCompass in QT Quick mobile App
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:
Code file - backend.cpp:
Image and Backend implementation:
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.
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;
Value = 180;
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.
@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?
Do you know one?
I added the <uses-permission/> statements to my AndroidManifest.xml file, but the testing's outcomes stayed the same.
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.
Is it necessary in Qt to use QSensorManager?
Should not, but I'm not expert in this area.
Deploying this code on Windows doesn't change the situation, just checked this out.