问题
I’m experimenting with Qt Positioning in Qt 5.3 RC on Android. This is sample of my code, where I create sources of position and satellites:
QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this);
if (source) {
QStringList posSourcesList = QGeoPositionInfoSource::availableSources();
qDebug() << "Position sources count: " << posSourcesList.count();
foreach (const QString &src, posSourcesList) {
qDebug() << "pos source in list: " << src;
}
source->startUpdates();
connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(positionUpdated(QGeoPositionInfo)));
}
//----------------------------------------------------------------------------------
QGeoSatelliteInfoSource *satelliteSource = QGeoSatelliteInfoSource::createDefaultSource(this);
if(satelliteSource)
{
QStringList sourcesList = QGeoSatelliteInfoSource::availableSources();
qDebug() << "Satellites sources count: " << sourcesList.count();
foreach (const QString &src, sourcesList) {
qDebug() << "source in list: " << src;
}
satelliteSource->startUpdates();
connect(satelliteSource, SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>)),
this, SLOT(satellitesInViewUpdated(QList<QGeoSatelliteInfo>)));
}
I get segmentation with the output:
D/Qt (16403): ../test_GPS/gpshandler.cpp:14 (GPSHandler::GPSHandler(QObject*)): Position sources count: 1
D/Qt (16403): ../test_GPS/gpshandler.cpp:16 (GPSHandler::GPSHandler(QObject*)): pos source in list: "android"
D/QtPositioning(16403): Regular updates using GPS
D/QtPositioning(16403): Regular updates using network
D/Qt (16403): ../test_GPS/gpshandler.cpp:37 (GPSHandler::GPSHandler(QObject*)): Satellites sources count: 1
D/Qt (16403): ../test_GPS/gpshandler.cpp:39 (GPSHandler::GPSHandler(QObject*)): source in list: "android"
F/Qt (16403): jnipositioning.cpp:496 (void satelliteUpdated(JNIEnv*, jobject, jobjectArray, jint, jboolean)): satelliteUpdated: source == 0
Here is the backtrace:
0 ?? /home/qtproj/build-test_GPS-Android_for_armeabi_v7a_GCC_4_8_Qt_5_3_0-Debug/libc.so 0x4010a8e8
1 abort /home/qtproj/build-test_GPS-Android_for_armeabi_v7a_GCC_4_8_Qt_5_3_0-Debug/libc.so 0x40108948
2 QMessageLogger::fatal(char const*, ...) const /opt/Qt-5.3.0_rc/5.3/android_armv7/lib/libQt5Core.so 0x75357ff6
3 satelliteUpdated(_JNIEnv*, _jobject*, _jobjectArray*, int, unsigned char) /opt/Qt-5.3.0_rc/5.3/android_armv7/plugins/position/libqtposition_android.so 0x751a8c08
4 ?? 0x40b3a910
5 ?? 0x40b3a910
When I’m creating only QGeoPositionInfoSource or only QGeoSatelliteInfoSource, this error doesn’t occur. Any suggestions?
回答1:
The same error is still present in 5.3.1. I don't have an explanation to offer, but the workaround here is to change the order of initialization of the sources.
- QGeoSatelliteInfoSource
- QGeoPositionInfoSource
So in your code that would be
QGeoSatelliteInfoSource *satelliteSource = QGeoSatelliteInfoSource::createDefaultSource(this);
if(satelliteSource) {
QStringList sourcesList = QGeoSatelliteInfoSource::availableSources();
qDebug() << "Satellites sources count: " << sourcesList.count();
foreach (const QString &src, sourcesList) {
qDebug() << "source in list: " << src;
}
satelliteSource->startUpdates();
connect(satelliteSource, SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>)),
this, SLOT(satellitesInViewUpdated(QList<QGeoSatelliteInfo>)));
}
QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this);
if (source) {
QStringList posSourcesList = QGeoPositionInfoSource::availableSources();
qDebug() << "Position sources count: " << posSourcesList.count();
foreach (const QString &src, posSourcesList) {
qDebug() << "pos source in list: " << src;
}
source->startUpdates();
connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(positionUpdated(QGeoPositionInfo)));
}
来源:https://stackoverflow.com/questions/23737781/qtpositioning-error-in-qt-5-3-rc-on-android