[PyKDE] PyQt Qthreads

Carles Pina i Estany carles at pina.cat
Tue Oct 31 20:12:05 GMT 2006


Hello,

On Oct/31/2006, Gregor Kling wrote:

> > QCustomEvent. Something like that (note that this is for Qt3, not Qt4, I
> > don't know if it has been changed):
> In this case, regrettably i'm using Qt4, and there are no longer these
> event-classes, i for one doesn't see them.
> I found some examples, but they all use the customevent stuff.
> So I have to dig deeper in the qt4-bibs.
> So you have not another hint because of that you does not use
> the qt4 port ?

some days ago I was porting a Python-Qt3 application to Python-Qt4, and
I used QCustomEvent. 

I copy-paste some part of code:
--------------
In thread:


class MyEvent(QtCore.QEvent):
        def setData(self,data):
                self.data=data

        def getData(self):
                return self.data

def sendInformation(id,s,gui):
        number=MyEvent.Type(MyEvent.User+id)
        event=MyEvent(number)
        event.setData(s)
        QtGui.QApplication.sendEvent(gui,event)



In main thread (to receive the events):
        def eventFilter(self,object,event):
                #TODO: save in a variable the message number and compare event.type with this variable!

                if (event.type() == QtCore.QEvent.Type(QtCore.QEvent.User+0)):
                        QtGui.QMessageBox.warning(self,"Error reading/writing files. Check permission of destination directory")
                        self.ui.progressBar.setProgress(0);
                        self.ui.process.setEnabled(True)
                        return True

                if (event.type() == QtCore.QEvent.Type(QtCore.QEvent.User+1)):
                        self.ui.progressBar.setValue(int(event.getData()))
                        return True

                if (event.type() == QtCore.QEvent.Type(QtCore.QEvent.User+2)):
                        self.ui.process.setEnabled(True)
                        self.ui.progressBar.setValue(0)
                        return True

bla bla bla...
---------------

I _think_ that works fine, I have not tested a lot. I saw some rare error
in one execution, not 100% sure if it was because this piece of code
(I don't think so)

Hope that will help...

-- 
Carles Pina i Estany		GPG id: 0x8CBDAE64
	http://pinux.info	Manresa - Barcelona




More information about the PyQt mailing list