Android上Qt 5.3 RC中的QtPositioning错误



我正在Android上的Qt 5.3 RC中试验Qt定位。这是我的代码示例,我在其中创建位置和卫星源:

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>)));
        }

我得到分段输出:

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

下面是回溯:

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

当我仅创建qgeopotioninfosource或仅QGeoSatelliteInfoSource时,此错误不会发生。有什么建议吗?

同样的错误在5.3.1中仍然存在。我没有解释,但这里的解决方法是改变源的初始化顺序。

  1. QGeoSatelliteInfoSource
  2. QGeoPositionInfoSource

在你的代码中应该是

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)));
}

相关内容

  • 没有找到相关文章

最新更新