[PyQt] QThread problem in linux

Stefan Stammberger sstammberger at web.de
Tue Mar 24 18:38:38 GMT 2009


I have a small QThread problem here. I'm trying to do a small progress bar in my app while my app is working. I have already tried QApplication.processEvents() which works very well in Windows
but screws everything up in Linux. When I use it my app receives key events only once in 10 tries, its completely unreliable. Now I have read in a kde mailing list that QApplication.processEvents()
is a bad thing anyway I have tried putting the progress bar in its own thread. This is my ProgreassBar class code:

class ProgressBarThread(QThread):
    def __init__(self, min, max, moduleName):
        self.progress = QProgressDialog("Loading " + moduleName, "Abort Loading", min, max, None);

    def setProgress(self, progress, labelText):
    def run(self):

And how I use it:

   def loadModule(self, moduleName):
        t = og.Timer()
        self.progress = ProgressBarThread(0, 8, moduleName)
        for m in self.moduleList:
            if m.name == moduleName:
                if m.hasDependencies: # load modules on wich the main module depends before the main module is loaded
                    for moduleDependencie in m.moduleDependencies:
                        for m2 in self.moduleList:
                            if m2.name == moduleDependencie:
                                self.progress.setProgress(2, "Loading Dependencie: " + moduleDependencie)

                self.progress.setProgress(4, "Loading " + moduleName)
                self.progress.setProgress(6, "Scan for models...")
                self.progress.setProgress(8, "Scan for materials")
                self.mainModule = m

        print "Time to load module: " + str(t.getMilliseconds() / 1000.0) + " seconds"
        del t

When using this I get a few warnings:

QPixmap: It is not safe to use pixmaps outside the GUI thread
QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread

And the worst:

X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 181

Extension: 155 (RENDER)

Minor opcode: 25 (RenderCompositeGlyphs32)

Resource id: 0x0

When I get this error no text in my application is drawn at all. The strange thing is,
when I have a cleanly booted system, it works very well the first time I start the application.
On the second time I don't get any text. Two screen shots:
How it looks without text: http://picasaweb.google.de/some.fusion/Lockenwickler?feat=directlink#5316822651416543426
And how it should look: http://picasaweb.google.de/some.fusion/Lockenwickler?feat=directlink#5316822694766353394

I don't know what I'm doing wrong here, I'm very new to the Threading stuff.

In case anybody wonders what my app is all about, its a game editor for an open source game.
http://www.youtube.com/watch?v=J-1ekVyv19o and http://www.youtube.com/watch?v=R0ZKMbLtXYY

Sorry for this long email!

Thank you very much!
Stefan Stammberger

More information about the PyQt mailing list