[PyQt] A Qt error pushed me out of Python

Gerard Vermeulen gerard.vermeulen at grenoble.cnrs.fr
Fri Apr 13 17:43:04 BST 2007


On Fri, 13 Apr 2007 21:25:02 +0530
Shriramana Sharma <samjnaa at gmail.com> wrote:

> Phil Thompson wrote:
> 
> > It's a fatal error and can't be changed.
> 
> Why not? If I do a mistake at the Python level, I always get the 
> interpreter back. Is it because the error occurs at the C++ level of
> Qt? Can't that error be caught and something meaningful printed? I
> mean, other Python modules written is C/C++ must have had to face
> this?
>
Yes, PyQt has improved enormously in catching errors during the almost
10 (?) years it is being developed.  Your mistake is an abuse of Qt: you
should always construct a QApplication before trying to display a widget
(you can paint to a pixmap, though).  Maybe your error can be caught
by checking inside *each* wrapped method whether an QApplication exists
before making the actual C++ call.  However, that means a lot of bloat
and checking for a case that should not occur in practice.

If you are using a version of PyQt before 4.2, you cannot really use
PyQt widgets like this because they do not respond to events, since
their is no event loop (you did not call yourQApplication._exec()).
PyQwt has a module 'iqt' that fakes an event loop in combination with
the readline module, see
http://pyqwt.sourceforge.net/doc5/iqt-intro.html

I think that PyQt-4.2 has also half the facility of faking the event
loop: you still have to use the readline module (this is what I think,
I did not test it) to make sure that events are handled.

Anyhow, if you want to use PyQt from the interpreter, I recommend
the use of a Python startup file as explained in iqt-intro.html.

Regards -- Gerard


More information about the PyQt mailing list