maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Python, Qt and LibConIC [RESOLVED] (https://talk.maemo.org/showthread.php?t=62631)

jaguilar 2010-09-20 22:59

Python, Qt and LibConIC [RESOLVED]
 
Is there a way to use LibIconIc in an Qt Python program?

This code runs ok:
Code:

#!/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 2010-09-21 00:19

Re: Python, Qt and LibConIC
 
My guess is you need to keep:

Code:

    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 2010-09-21 00:37

Re: Python, Qt and LibConIC
 
It worked like a charm....despite the fact that it's a ugly workaround!

:-) 2010-09-21 10:53

Re: Python, Qt and LibConIC
 
Another GStreamer + PyQt hint can be found here:

http://www.diotavelli.net/PyQtWiki/U...amer_with_PyQt

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


All times are GMT. The time now is 07:38.

vBulletin® Version 3.8.8