×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    95

    liblocation does not work in consol app?

    hi everybody;
    i wrote a liblocation class and it works fine in any Gui app, but when
    i try to apply it in a console application the calss does not work.
    is it possible to run liblocation code in console application?

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: liblocation does not work in consol app?

    Why not?
    Code:
    #include <glib-object.h>
    #include <conic/conic.h>
    #include <dbus/dbus-glib-lowlevel.h>
    
    #include <QCoreApplication>
    #include <QDebug>
    
    static void
    my_connection_handler(ConIcConnection *connection,
                          ConIcConnectionEvent *event,
                          gpointer user_data)
    {
        Q_UNUSED(connection);
        Q_UNUSED(user_data);
    
        qDebug("Connection event has been catched. Leaving.");
        QCoreApplication::quit();
    }
    
    int
    main (int argc,
          char **argv)
    {
        DBusConnection *conn;
        DBusError err;
    
        dbus_error_init(&err);
        conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
        if (conn) {
            /* This is crucial for using conic library */
            dbus_connection_setup_with_g_main(conn, NULL);
        } else {
            qDebug("Unable to connect to the D-BUS daemon: %s", err.message);
            dbus_error_free(&err);
        }
    
        int ret;
        QCoreApplication app(argc, argv);
    
        gboolean success = FALSE;
        ConIcConnection *connection = con_ic_connection_new();
        g_signal_connect(G_OBJECT(connection), "connection-event",
                         G_CALLBACK(my_connection_handler), NULL);
    
        success = con_ic_connection_connect(connection, CON_IC_CONNECT_FLAG_NONE);
        if (!success)
            qDebug("Request for connection failed");
        else
            qDebug("Successful request for connection");
    
        ret = app.exec();
    
        success = con_ic_connection_disconnect(connection);
        g_object_unref(connection);
    
        qDebug("Bye!");
    
        return ret;
    }

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    95

    Re: liblocation does not work in consol app?

    Dear ,
    liblocation not libconic!

  4. #4
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: liblocation does not work in consol app?

    Quote Originally Posted by mismael View Post
    Dear ,
    liblocation not libconic!
    Well, no difference.

  5. #5
    Registered User
    Join Date
    Oct 2009
    Posts
    95

    Re: liblocation does not work in consol app?

    no i used liblocation in a QCoreApplication but it does not work and when i used QApplication
    it worked fine .
    i think this becuase of the use of g_Signal_connect.

  6. #6
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: liblocation does not work in consol app?

    Quote Originally Posted by mismael View Post
    no i used liblocation in a QCoreApplication but it does not work and when i used QApplication
    it worked fine .
    i think this becuase of the use of g_Signal_connect.
    conic example is also using g_signal_connect and it works fine.

  7. #7
    Registered User
    Join Date
    Oct 2009
    Posts
    95

    Re: liblocation does not work in consol app?

    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

  8. #8
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    82

    Re: liblocation does not work in consol app?

    Quote Originally Posted by mismael View Post

    the code used in the main func...
    Code:
    QCoreApplication a(argc, argv);
    Did you have a.exec() too, so that you'll have the mainloop?

  9. #9
    Registered User
    Join Date
    Oct 2009
    Posts
    95

    Re: liblocation does not work in consol app?

    yes i have
    return a.exec();
    it is a strang thing it shloud work but it did not i think that QCoreApplication may be does not
    support g_signal_connect

  10. #10
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    82

    Re: liblocation does not work in consol app?

    Quote Originally Posted by mismael View Post
    it is a strang thing it shloud work but it did not i think that QCoreApplication may be does not
    support g_signal_connect

    To proceed with troubleshooting - were you running the command line program as root by any chance? Or did you "su - user" before running it?

  11. #11
    Registered User
    Join Date
    Oct 2009
    Posts
    95

    Re: liblocation does not work in consol app?

    no, i am not a root user .
    i think if you have a time , take my class and try it your self, if it worked tell me what you did.

  12. #12
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    82

    Re: liblocation does not work in consol app?

    Quote Originally Posted by mismael View Post
    no, i am not a root user .
    i think if you have a time , take my class and try it your self, if it worked tell me what you did.
    Please submit a self-contained example that compiles and I'll take a stab at debugging it.

  13. #13
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: liblocation does not work in consol app?

    A working example was submitted to this thread:
    http://discussion.forum.nokia.com/fo...d.php?t=194755

Similar Threads

  1. My signal() doesn't work for standalone app
    By olliwang in forum Symbian
    Replies: 1
    Last Post: 2008-11-13, 14:13
  2. protect app: work for paid only
    By tgkprog@gmail.com in forum Mobile Java General
    Replies: 0
    Last Post: 2007-08-28, 00:32
  3. symbian signed testing problem.
    By anglina in forum Symbian
    Replies: 0
    Last Post: 2007-02-01, 10:15
  4. Why my socket app doesn't work with some network operator/
    By joke_playwiz in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2005-07-14, 21:17
  5. Camera App can not work on nokia7610?
    By redglove in forum Symbian
    Replies: 0
    Last Post: 2005-05-24, 07:36

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×