QCompass in QT Quick mobile App
-
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:
Code file - backend.cpp:
Image and Backend implementation:
Timer 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;
}
void Backend::checkReading()
{
Value = 180;
} -
@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. -
@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? -
-
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.
-
@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.