PDA

View Full Version : Python, Qt and LibConIC [RESOLVED]


jaguilar
09-20-2010, 06:59 PM
Is there a way to use LibIconIc in an Qt Python program?

This code runs ok:
#!/usr/bin/python2.5
import conic
import gobject, dbus
from dbus.mainloop.glib import DBusGMainLoop

def connection_cb(connection, event):
print "connection_cb(%s, %s)" % (connection, event)

status = event.get_status()
error = event.get_error()
iap_id = event.get_iap_id()
bearer = event.get_bearer_type()

if status == conic.STATUS_CONNECTED:
print "(CONNECTED (%s, %s, %i, %i)" % (iap_id, bearer, status, error)
elif status == conic.STATUS_DISCONNECTED:
print "(DISCONNECTED (%s, %s, %i, %i)" % (iap_id, bearer, status,error)
elif status == conic.STATUS_DISCONNECTING:
print "(DISCONNECTING (%s, %s, %i, %i)" % (iap_id, bearer, status,error)


if __name__ == "__main__":
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
connection = conic.Connection()
connection.set_property("automatic-connection-events", True)
connection.connect("connection-event", connection_cb)
gobject.MainLoop().run()


But if I change it for Qt (using DbusQtMainLoop and QCoreApplication instead of DbusGMainLoop and gobject), I receive a segmentation fault.

fatalsaint
09-20-2010, 08:19 PM
My guess is you need to keep:


loop = gobject.MainLoop()
gobject.threads_init()
context = loop.get_context()


In your app. I have the same problem with MAFW and gstreamer bindings. Because they are applications revolving around gobject you need a gobject loop or you'll segfault. I modified your code above using QCoreApplication and DbusQtMainLoop as you suggested and got it to work including the code above in the "__main__" method. Adding those three lines you start a gobject MainLoop as a thread in the background so it doesn't interfere with your app, but it's obviously kind of ugly (but necessary) having to import gobject in a QT app.

jaguilar
09-20-2010, 08:37 PM
It worked like a charm....despite the fact that it's a ugly workaround!

:-)
09-21-2010, 06:53 AM
Another GStreamer + PyQt hint can be found here:

http://www.diotavelli.net/PyQtWiki/Using_GStreamer_with_PyQt

It would be good to collect these interoperability solutions somewhere. :-)