[PyQt] signal

John Beuving johnbeuving at gmail.com
Thu Feb 10 15:17:37 GMT 2011



Hi,

I have the following error when running my C++ code from python.
The C++ code is a multiple inheritance class. It is a worker thread 
which has to emit events.
Why doesn't this work ?

File "test.py", line 165, in __init__
     self.didSomething.connect(self.handletrigger)
TypeError: pyqtSignal must be bound to a QObject, not 'ImageWriter'

C++ header file:

         class QtWorker: public QObject, public Worker {
         public:
             QtWorker(const std::string& name=""): Worker(name), 
p_widget(0) {}
             virtual ~QtWorker() {}

             QWidget* GetWidget() {return p_widget;}

         protected:
             QWidget* p_widget;
         };


SIP Code:

namespace core
{
     class QtWorker: QObject, core::Worker
     {
%TypeHeaderCode
#include "core/Qtworker.h"
%End
         public:
             QtWorker(const string& name);

             void *GetWidget();

     };
};

Python Code:

class ImageWriter(core.QtWorker):

     didSomething = pyqtSignal()

     def __init__(self):
         super(ImageWriter,self).__init__()
         self.didSomething.connect(self.handletrigger)

     def Process(self):
         self.didSomething.emit()
         return True

     def handletrigger(self):
         print "ImageWriter signal received"



More information about the PyQt mailing list