QT5 Android Positioning, not working without SIM card
-
wrote on 9 Jun 2022, 07:14 last edited by
Using Positioning in Android, works great if the phone/tablet has a SIM card installed.
Without a SIM card the slots never gets called!Is this a QT or pure Android problem?
Is there any way around it?Without SIM card I do not get any error (not slots are called, QGeoPositionInfoSource::createDefaultSource() works), so I don't know how to tell the user why they cannot get the position!
QT 5.15.2, (built on Linux Mint), NDK 21.3.6528147
QGeoPositionInfoSource *gpsSrc; gpsSrc = QGeoPositionInfoSource::createDefaultSource(0); if (gpsSrc) { // Get here regardless of SIM card or not gpsSrc->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods); connect(gpsSrc, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo))); connect(gpsSrc, SIGNAL(error(QGeoPositionInfoSource::Error positioningError)), this, SLOT(positionError(QGeoPositionInfoSource::Error positioningError))); connect(gpsSrc, SIGNAL(QGeoPositionInfoSource::updateTimeout()), this, SLOT(updateTimeout())); // Without SIM card none of the slots gets called }
-
Using Positioning in Android, works great if the phone/tablet has a SIM card installed.
Without a SIM card the slots never gets called!Is this a QT or pure Android problem?
Is there any way around it?Without SIM card I do not get any error (not slots are called, QGeoPositionInfoSource::createDefaultSource() works), so I don't know how to tell the user why they cannot get the position!
QT 5.15.2, (built on Linux Mint), NDK 21.3.6528147
QGeoPositionInfoSource *gpsSrc; gpsSrc = QGeoPositionInfoSource::createDefaultSource(0); if (gpsSrc) { // Get here regardless of SIM card or not gpsSrc->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods); connect(gpsSrc, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo))); connect(gpsSrc, SIGNAL(error(QGeoPositionInfoSource::Error positioningError)), this, SLOT(positionError(QGeoPositionInfoSource::Error positioningError))); connect(gpsSrc, SIGNAL(QGeoPositionInfoSource::updateTimeout()), this, SLOT(updateTimeout())); // Without SIM card none of the slots gets called }
wrote on 9 Jun 2022, 14:23 last edited byAdditional information:
When debugging on the phone without SIM card I get:
W libtid_armeabi-v7a.so: QObject::connect: No such signal QGeoPositionInfoSourceAndroid::error(QGeoPositionInfoSource::Error positioningError) in ../mobile/dlg_main.cpp:87 W libtid_armeabi-v7a.so: QObject::connect: (receiver name: 'DLG_MAIN') W libtid_armeabi-v7a.so: QObject::connect: No such signal QGeoPositionInfoSourceAndroid::QGeoPositionInfoSource::updateTimeout() in ../mobile/dlg_main.cpp:90 W libtid_armeabi-v7a.so: QObject::connect: (receiver name: 'DLG_MAIN') D QtPositioning: Regular updates using GPS 50
With SIM card (same phone):
W libtid_armeabi-v7a.so: QObject::connect: No such signal QGeoPositionInfoSourceAndroid::error(QGeoPositionInfoSource::Error positioningError) in ../mobile/dlg_main.cpp:369 W libtid_armeabi-v7a.so: QObject::connect: (receiver name: 'DLG_MAIN') D QtPositioning: Regular updates using GPS 50
-
Looks like your signal-slot connections are wrong. If only possible, use functor-based connections https://doc.qt.io/qt-5/signalsandslots-syntaxes.html it will fail to compile if you use wrong signal / slot functions.
I don't know if it will help in finding location, but it sure will help in getting slots to work.
-
wrote on 21 Jun 2022, 11:16 last edited by
Hi @MartinGU
Not sure if you already solved your issue, or if it's still relevant for you.
First of all, I do not think that you can use parameter names in signal/slot connection, like you do it for error signal.
The correct way would be to do as follows:connect(gpsSrc, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo))); connect(gpsSrc, SIGNAL(error(QGeoPositionInfoSource::Error)), this, SLOT(positionError(QGeoPositionInfoSource::Error))); connect(gpsSrc, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
Hope this will allow you to catch the errors, if there are any.
After setting preferred positioning methods you can also query them, as well as supported positioning methods, just to make sure that everything is set up correctly.
To do so, call:gpsSrc->preferredPositioningMethods(); gpsSrc->supportedPositioningMethods();
Make sure that both outputs contain
QGeoPositionInfoSource::SatellitePositioningMethods
value.Last but not least, in your log I see
D QtPositioning: Regular updates using GPS 50
which indicates that Android at least tries to start positioning updates using GPS in both cases (with and without SIM card). If GPS sensor performs a cold boot, it might take quite some time to actually start getting GPS updates. It's possible that with the SIM card you get initial updates based on the rough position from the cell.