[PyQt] signal
John Beuving
johnbeuving at gmail.com
Fri Feb 11 14:31:09 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"
>
I tried to investigate the problem I had further. The problem is that
there is no way to cast the QtWorker to a QObject.
The reason for this is that in the list of supers for the QtWorker
object there is no 'correct' reference to QObject.
When comparing the list of types in the generated code of QtCore and the
list of supertypes in my generated there seems to be a problem.
To be more precise:
In the generated cpp code of QtWorker
/* Define this type's super-types. */
static sipEncodedTypeDef supers_core_QtWorker[] = {{96, 0, 0}, {26, 255,
1}};
This means that there are 2 supers, One from the own module typenumber
26, as found in the header file:
#define sipType_core_Worker sipModuleAPI_PyMPT.em_types[26]
And the first one from another module (index 0) index 96
#define sipType_QList_0101QAbstractTransition
sipModuleAPI_QtCore.em_types[96]
Which is obviously not the QObject I'm looking for. In the init procudre
of my module I can also see that a superclass type is register from
QList::QAbstractTransition
But this clearly is very wrong.
The number 96 can be found in my own code correctly:
#define sipType_QObject
sipModuleAPI_PyDySI_QtCore->em_types[96]
However this type is created after the QtWorker
My question is, where does sip get these numbers, and how can I fix this.
More information about the PyQt
mailing list