QCompass in QT Quick mobile App
-
wrote on 6 Nov 2020, 17:58 last edited by
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: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. -
wrote on 7 Nov 2020, 21:21 last edited by
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;
} -
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. -
wrote on 10 Nov 2020, 11:40 last edited by
@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? -
@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? -
wrote on 10 Nov 2020, 16:24 last edited by
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.
-
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.
-
wrote on 11 Nov 2020, 18:08 last edited by
Deploying this code on Windows doesn't change the situation, just checked this out.
4/8