here are the code i used with QCoreApplication but does not connect to the gps.
Code:
#include "gps.h"
#include <QDebug>
#ifdef Q_WS_HILDON
Gps::Gps(QObject *parent) :
QObject(parent)
{
control = location_gpsd_control_get_default();
device = (LocationGPSDevice *)g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
g_object_set(G_OBJECT(control),
"preferred-method", LOCATION_METHOD_USER_SELECTED,
"preferred-interval", LOCATION_INTERVAL_DEFAULT,
NULL);
g_signal_connect(control, "error-verbose", G_CALLBACK(on_error), (Gps*)this);
g_signal_connect(device, "changed", G_CALLBACK(on_changed), (Gps*)this);
//g_signal_connect(control, "gpsd-stopped", G_CALLBACK(on_stop), loop);
//start();
}
Gps::~Gps()
{
if(control)
delete control;
if(device)
delete device;
}
void on_changed(LocationGPSDevice *device, Gps* data)
{
if (!device)
return;
if (device->fix) {
if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET && device->fix->eph <= 500000) {
qDebug("lat = %f, long = %f", device->fix->latitude, device->fix->longitude);
data->m_longitude = device->fix->longitude;
data->m_latitude = device->fix->latitude;
emit data->gpsChanged();
// qDebug()<<"statlite mode is =========="<<device->fix->mode;
// qDebug()<<"the status is ============"<<device->status;
// qDebug()<<"satalites in view====="<<device->satellites_in_view;
// qDebug()<<"satalites in use====="<<device->satellites_in_use;
// qDebug()<<"online ========= "<< device->online;
qDebug()<<"eph==========="<<device->fix->eph;
}
if(device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET )
{
data->m_track = device->fix->track;
}
}
}
void Gps::stop()
{
location_gpsd_control_stop(control);
}
bool Gps::start()
{
location_gpsd_control_start(control);
return FALSE;
}
void on_error(LocationGPSDControl *control, LocationGPSDControlError error, Gps* user_data)
{
switch (error) {
case LOCATION_ERROR_USER_REJECTED_DIALOG:
qDebug("User didn't enable requested methods");
break;
case LOCATION_ERROR_USER_REJECTED_SETTINGS:
qDebug("User changed settings, which disabled location");
break;
case LOCATION_ERROR_BT_GPS_NOT_AVAILABLE:
qDebug("Problems with BT GPS");
break;
case LOCATION_ERROR_METHOD_NOT_ALLOWED_IN_OFFLINE_MODE:
qDebug("Requested method is not allowed in offline mode");
break;
case LOCATION_ERROR_SYSTEM:
qDebug("System error");
break;
}
}
double Gps::getLatitude()
{
return m_latitude;
}
double Gps::getLongitude()
{
return m_longitude;
}
double Gps::getTrack()
{
return m_track;
}
int Gps::getStatus()
{
qDebug()<<"int Gps::getStatus()";
if(device->status == LOCATION_GPS_DEVICE_STATUS_FIX)
return 1;
else
return 0;
}
#endif
the code used in the main func...
Code:
QCoreApplication a(argc, argv);
when i used the same code but with QApplication it worked fine .
where are the problem