Sending custom PyQt signals?
        Posted  
        
            by Enfors
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Enfors
        
        
        
        Published on 2010-04-06T14:14:20Z
        Indexed on 
            2010/04/06
            18:33 UTC
        
        
        Read the original article
        Hit count: 507
        
I'm practicing PyQt and (Q)threads by making a simple Twitter client. I have two Qthreads.
- Main/GUI thread. 
- Twitter fetch thread - fetches data from Twitter every X minutes. 
So, every X minutes my Twitter thread downloads a new set of status updates (a Python list). I want to hand this list over to the Main/GUI thread, so that it can update the window with these statuses.
I'm assuming that I should be using the signal / slot system to transfer the "statuses" Python list from the Twitter thread, to the Main/GUI thread. So, my question is twofold:
- How do I send the statuses from the Twitter thread? 
- How do I receive them in the Main/GUI thread? 
As far as I can tell, PyQt can by default only send PyQt-objects via signals / slots. I think I'm supposed to somehow register a custom signal which I can then send, but the documentation on this that I've found is very unclear to a newbie like me. I have a PyQt book on order, but it won't arrive in another week, and I don't want to wait until then. :-)
I'm using PyQt 4.6-1 on Ubuntu
Update:
This is an excert from the code that doesn't work. First, I try to "connect" the signal ("newStatuses", a name I just made up) to the function self.update_tweet_list in the Main/GUI thread:
QtCore.QObject.connect(self.twit_in,
                       QtCore.SIGNAL("newStatuses (statuses)"),
                       self.update_tweet_list)
Then, in the Twitter thread, I do this:
self.emit(SIGNAL("newStatuses (statuses)"), statuses)
When this line is called, I get the following message:
QObject::connect: Cannot queue arguments of type 'statuses'
(Make sure 'statuses' is registered using qRegisterMetaType().)
I did a search for qRegisterMetaType() but I didn't find anything relating to Python that I could understand.
© Stack Overflow or respective owner