View Single Post
Posts: 2 | Thanked: 5 times | Joined on Apr 2010 @ Pori, Finland
#13
Originally Posted by brink View Post
Well, I figured it out also. I guess there was no documentation because it was so simple.

Liblocation (and any glib libs, as far as I understood) will run fine inside the Qt event loop. You basically just use the library as you would in a Gtk application.
Hi

I am trying to use location API in a very simple Python QT application but it ends up with a segmentation fault. The code is actually modified from the version using gobject main loop.

It seems that the code crashes (on N900) when I call control.start(). The code can not be obviously tested on scratchbox because there is no GPS available. Any ideas what is wrong?

-- JariM

Code:
import sys
import pdb
from PyQt4 import QtCore, QtGui
import location


def on_error(control, error, data):
    print "location error: %d... quitting" % error
    data.quit()

def on_changed(device, data):
    if not device:
        return
    if device.fix:
        if device.fix[1] & location.GPS_DEVICE_LATLONG_SET:
            print "lat = %f, long = %f" % device.fix[4:6]
            data.stop()

def on_stop(control, data):
    print "quitting"
    data.quit()

def start_location(data):
    data.start()
    return False
    
    
#loop = gobject.MainLoop()

app = QtGui.QApplication(sys.argv)
myWindow = QtGui.QMainWindow()

control = location.GPSDControl.get_default()
device = location.GPSDevice()
control.set_properties(preferred_method=location.METHOD_USER_SELECTED, preferred_interval=location.INTERVAL_DEFAULT)

control.connect("error-verbose", on_error, app)
device.connect("changed", on_changed, control)
control.connect("gpsd-stopped", on_stop, app)
pdb.set_trace()
print device.status

control.start()
#gobject.idle_add(start_location, control)
#loop.run()


myWindow.show()

# Now we can start the UI.
sys.exit(app.exec_())