[PyQt] QThread problem in linux

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


Hi,

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):
        QThread.__init__(self)
        self.progress = QProgressDialog("Loading " + moduleName, "Abort Loading", min, max, None);
        self.progress.setWindowModality(Qt.WindowModal)

    def setProgress(self, progress, labelText):
        self.progress.setLabelText(labelText)
        self.progress.setValue(progress)
        
    def run(self):
        self.progress.show()
        self.exec_()


And how I use it:

   def loadModule(self, moduleName):
        t = og.Timer()
        
        self.progress = ProgressBarThread(0, 8, moduleName)
        self.progress.start()
        
        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)
                                m2.load()
                                self.modelSelectionDialog.scanDirForModels(m2.moduleRoot)
                                self.materialSelectionDialog.scanDirForMaterials(m2.moduleRoot)
                                self.mainModuledependencieList.append(m2)

                self.progress.setProgress(4, "Loading " + moduleName)
                m.load()
                self.progress.setProgress(6, "Scan for models...")
                self.modelSelectionDialog.scanDirForModels(m.moduleRoot)
                self.progress.setProgress(8, "Scan for materials")
                self.materialSelectionDialog.scanDirForMaterials(m.moduleRoot)
                self.mainModule = m
                self.moduleExplorer.setCurrentModule(m)

        self.progress.quit()
        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