PDA

View Full Version : If GPS is unavailable, application crashes!!!



wizarda
25th January 2011, 10:24
Hi All,

If I deselect all GPS methods in Settings >> Application Manager >> Positioning >> Positioning methods (which I think results the same as no GPS available) in my N8 phone, my application crashes.

code is something like:
in .h file
QGeoPositionInfoSource *locationDataSource;

in .cpp file
if (!locationDataSource)
{
locationDataSource = QGeoPositionInfoSource::createDefaultSource(this);
locationDataSource->setPreferredPositioningMethods(QGeoPositionInfoSou rce::AllPositioningMethods);

...

locationDataSource->startUpdates();

}

The application crashes as soon as the controller reaches "locationDataSource->setPreferredPositioningMethods(QGeoPositionInfoSou rce::AllPositioningMethods);"
as I think QGeoPositionInfoSource::AllPositioningMethods would not match anything.

Is there a way to handle this problem so that my application does not crash even if GPS is unavailable?

I have tried used exception handling but even that has not worked. I don't exactly know what kind of exception this case would throw and thus I used catch(const std::exception& e) and obviously it has not worked.

Can anyone please help me with this problem?

Thanks.

wysota
25th January 2011, 10:28
So maybe you should check first if the pointer returned is valid before using it?

nish
25th January 2011, 10:35
locationDataSource = QGeoPositionInfoSource::createDefaultSource(this);
locationDataSource->setPreferredPositioningMethods(QGeoPositionInfoSou rce::AllPositioningMethods);

Are you serious? what happened to the basic NULL checking? As wysota pointed out its a null pointer problem. But really.. how are you writing GPS application without Basic NULL checking?

wizarda
25th January 2011, 12:34
Thanks guys...

reachsakthi
14th May 2011, 12:29
Wizarda.. did u solve this issue... can you help me with pointers
Crashed with " Process 758, thread 759 stopped at 0x78e3d4bc: A data abort exception has occurred."
Finished.

####### Sample Code ########
locationDataSource =
QGeoPositionInfoSource::createDefaultSource(this); >>>>>>>>> Code crashed immediately after this statement.. .

if (locationDataSource == NULL)
{
QMessageBox m;
m.setText("Location source NULL ");
m.exec();
}

reachsakthi
16th May 2011, 10:58
Solved,Initialize the locationDataSource = NULL