This app utilizes QtPositioning.
In main.cpp, I do an initial call to get the users location:
FileIOqt myFileIO;
gpsio myGpsIO(&myFileIO);
myGpsIO.gpsOneShot();
FileIOqt myFileIO;
gpsio myGpsIO(&myFileIO);
myGpsIO.gpsOneShot();
To copy to clipboard, switch view to plain text mode
FileIOqt and gpsio are defined in their respective fileio.cpp/.h and gpsio.cpp/.h...
In gpsOneShot(), I do:
if (sourceOneShot) {
connect(sourceOneShot, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(oneShotPosition(QGeoPositionInfo)));
sourceOneShot->startUpdates();
}
if (sourceOneShot) {
connect(sourceOneShot, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(oneShotPosition(QGeoPositionInfo)));
sourceOneShot->startUpdates();
}
To copy to clipboard, switch view to plain text mode
In oneShotPosition, I get the relevant data and update my QML text fields where necessary. Then, I call stopOneShotGPS() which in turn calls a javascript function:
QObject *root
= myFileIO
->engine.
rootObjects().
first();
QObject *root = myFileIO->engine.rootObjects().first();
QVariant returnedVal;
QMetaObject::invokeMethod(root,"gpsOneShotUpdate",Q_RETURN_ARG(QVariant, returnedVal));
To copy to clipboard, switch view to plain text mode
The gpsOneShotUpdate javascript function basically sets a few variables, and shows a new QML page.
ALL THIS WORKS fine...when it's all in one QML file.
What I need now..is to be able to still call the JavaScript functions from CPP, even when they are moved outside (but imported into) the QML.
Bookmarks