Hi Denis,

At least in the past it worked as I remember having tested the use case. Do you 
have a backtrace?

And yes, Ryan's comment is correct in that you are missing essential error 
checking in your code.

--
Alex

________________________________________
From: Denis Shienkov <[email protected]>
Sent: Wednesday, 24 October 2018 6:31:59 PM
To: [email protected]; Alex Blasche; BogDan Vatra
Subject: Does QGeoPositionInfoSource work from an Android service?

Hi all,

I tried to make it work from the Android service:


#include <QAndroidService>

#include <QGeoPositionInfoSource>

#include <QLoggingCategory>

#include <QTimer>


Q_LOGGING_CATEGORY(APP, "bug.svc")


int main(int argc, char *argv[])

{

    QAndroidService::setAttribute(Qt::AA_EnableHighDpiScaling);

    QAndroidService app(argc, argv);


    qCDebug(APP) << "I'm service";


    const auto t = new QTimer(qApp);

    QCoreApplication::connect(t, &QTimer::timeout, []() {

        static int counter = 0;

        qCWarning(APP) << "CNT:" << counter;

        ++counter;

    });

    t->start(1000);


    const auto ps = QGeoPositionInfoSource::createDefaultSource(qApp);

    QCoreApplication::connect(ps, &QGeoPositionInfoSource::positionUpdated,

                              [=](const QGeoPositionInfo &update) {

        const auto coord = update.coordinate();

        qCDebug(APP) << "CRD:" << coord;

    });

    ps->setUpdateInterval(3000);

    ps->startUpdates();


    return app.exec();

}

but a service, seems, crashed at all (at least I did not see any debugging log 
from the logcat).

But if I try to cemment out all code, related to the locations, and keep a code 
with the timer,
then I see the counters output.

I tried it on Android x86 && Qt 5.11.2 && Android API 21.

E.g. from here: 
https://stackoverflow.com/questions/13345002/locationmanager-in-service
I see that it is possible to wotk with Android's LocationManager from the 
service... BUT,
it does not work with QGeoPositionInfoSource!

BR,
Denis




_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to