Qt Android GPS update Timeout every second time



  • I have GPS code that work sometime. Anyone what could be wrong?

    Thanks

    #include "MainWindow.h"
    #include "ui_MainWindow.h"
    #include <QDebug>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        _positionSource = QGeoPositionInfoSource::createDefaultSource(this);
    //    _positionSource->setPreferredPositioningMethods(QGeoPositionInfoSource::
    //                                                  AllPositioningMethods);
        connect(_positionSource, &QGeoPositionInfoSource::positionUpdated, this, &MainWindow::onPositionUpdated );
        connect(_positionSource, &QGeoPositionInfoSource::updateTimeout, this, &MainWindow::onPositionTimeout );
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_pushButton_clicked()
    {
        _positionSource->requestUpdate(5000);
    }
    
    void MainWindow::onPositionUpdated(const QGeoPositionInfo &update)
    {
        ui->pushButton->setText(update.coordinate().toString());
        qDebug() << "updated";
    }
    
    void MainWindow::onPositionTimeout()
    {
        ui->pushButton->setText("Timeout");
        qDebug() << "timeout";
    }
    
    


  • @sharethl Seems increase time out to 10 seconds will increase the possibility of success


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.