[PyKDE] KTrader woes?

Sundance sundance at ierne.eu.org
Thu Sep 11 02:46:01 BST 2003

I heard Jim Bublitz said:

> It returns a 7 item list here (exact same code as above in a
> KApplication).

Ah. The 'in a KApplication' part may actually be the crucial point. :)

> Can you provide a *short*, complete example
> program that segfaults on this?

Already did. 0:)

#!/bin/env python
from kio import *
offer = KTrader.self().query("text/html")
print "If you read this, then it has worked. Uh."

I assume that it is not expected to work outside a KApplication, then? 
Maybe there should be a way to raise an exception rather than crash 
when this is called outside a KApplication...? That was the behavior I 
expected anyway, so when I tried the KTrader trick on its own I assumed 
that it would either 1) work on its own, or 2) require some 
QApplication-like class to have been instanciated, in which case it 
would warn me.

Guess I was wrong about the 'warn me' part.

> There are a couple of programs in examples/ that use KTrader
> (pyParts.py, pyParts_1.py don't work too well at the moment
> though). If you run examples/mimetype.py, the OfferList tab
> results are from a KTrader call -- does that work?

It does.
I rewrote my little example above adding a KApplication instanciation 
just before the call to KTrader.self().query, and it works, whee!

Well, more precisely, it works if I copy the KCmdLineArgs.init line from 
mimetype.py. If I call KApplication([], "SomeName") it dies. Apparently 
KApplication REQUIRES a non-empty list as its first argument, unlike 
QApplication (with which the [] trick works).

Alright, so. Erm. :) I may be wrong about this as well, but I still sort 
of think there are more elegant ways to let the user know he's done 
something wrong than crash the full interpreter. =)

Is there any way we can help make it so?

-- S.

More information about the PyQt mailing list