2011-01-16 10 views
9

Desidero connettere un segnale nel thread in background a uno slot nel thread della GUI in modo pithonic.Come connettere lo slot PyQt dal thread in background al thread GUI

Ho il seguente snippet di codice.

from PyQt4.QtCore import * 
class CompanyPresenter(QObject): 
    fieldChangeSignal = pyqtSignal(str, str) 
    def __init__(self,model,view): 
     self.model = model  # a CompanyModel 
     self.view = view   # a CompanyView 
     self.fieldChangeSignal.connect(view.setField) 

ottengo questo errore (sulla linea di connessione)

TypeError: pyqtSignal deve essere associato a un QObject, non e 'CompanyPresenter'

Ma CompanyPresenter eredita da QObject quindi è una QObject. Che cosa sta succedendo?

(Desidero che Presenter e GUI vengano eseguiti in thread diversi alla fine, ma non sono ancora arrivato a destinazione. Non è ancora disponibile il threading).

risposta

23

si dimenticato questo:

def __init__(self,model,view): 
    super(CompanyPresenter, self).__init__() # this!!!!!!!!! 

aggiungere questo funzionerà (testato)

.
Problemi correlati