views:

127

answers:

1

As per examples seen online, I've created a Worker thread. I'm looking for a thread to run my GUI while one thread executes my code. Worker thread is defined as:

class Worker(QThread):

    def __init__(self, parent = None):
        QThread.__init__(self, parent)
        self.exiting = False
        self.size = QSize(0, 0)

    def __del__(self):
        self.exiting = True
        self.wait()

pretty simple. Within my Window class, I have this line in the __init__ function: self.thread = Worker(). However, I never do anything with that self.thread afterwards. What am I supposed to be doing with it? This does not seem to be laid out as nicely as other threading mechanisms..

+2  A: 

I imagine you're looking at the example here? But that example does "do something with that thread afterwards" -- it hooks up methods to respond to the signals the thread sends when it starts and finishes, in the class Worker it defines a run method that draws random stars , etc etc. Not sure what you think is wrong with how this is "laid out"?

Alex Martelli
Actually that was not the example I'd been pointed to. Interesting. I don't understand, however, how in that example both the worker thread and the window thread seem to be drawing to the screen, since I imagine you need to be within the Window class to draw on the Window?
Chris
The painting on the windows' pixmap is done in the window's method `addImage`, which is connected to a signal emitted by the worker when a star is ready. Do read the text as well as the code in the example I point to, I think it does explain things pretty well!
Alex Martelli
Reading it through a few times is making a bit more sense.. Is it possible to emit a signal with something other than a QT type? Could I emit a signal from my thread that sends back two lists of QT objects?
Chris
Nevermind this, I think I figured that out :)
Chris