[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Problem with custom class derived from QObject as signal parameter
From: Phil Thompson <phil () riverbankcomputing ! com>
Date: 2015-07-14 16:29:04
Message-ID: ff66b3d955f8d0a167a8bc301dcab06d () riverbankcomputing ! com
[Download RAW message or body]
On 14/07/2015 12:01 pm, Johan Fläckman wrote:
> Hi, I have a C++ class that emits a pointer to a class deriving from
> QObject. The instance ends up in python slots as a QObject (and not to
> the
> class deriving from it). Can someone help me figure out what I have
> done
> wrong?
>
> Python 2.7, 64bit
> Windows 7
>
> Qt 5.4.1
> PyQt 5.4.1
> SIP 4.16.7
>
>
> I tried to make a minimal repro case;
>
>
> *C++*
> class Foo : public QObject
> {
> Q_OBJECT
> public:
> explicit Foo(QObject* parent = 0) : QObject(parent) { }
> ~Foo() {};
> };
>
> class Emitter : public QObject
> {
> Q_OBJECT
> public:
> Emitter() {}
> ~Emitter() {}
> void AddItem() { emit itemAdded( new Foo ); }
>
> Q_SIGNALS:
> void itemAdded(Foo*);
> };
>
> *SIP*
> %Module(name=pyqt_test, call_super_init=True)
>
> %ModuleCode
> #include <test.h>
> %End
>
> %Import QtCore/QtCoremod.sip
>
> class Foo : public QObject
> {
> %TypeHeaderCode
> #include <test.h>
> %End
> public:
> explicit Foo(QObject *parent /TransferThis/ = 0);
> ~Foo();
> };
>
> class Emitter : public QObject
> {
> %TypeHeaderCode
> #include <test.h>
> %End
> public:
> Emitter();
> virtual ~Emitter();
> void AddItem();
>
> Q_SIGNALS:
> void itemAdded(Foo*);
> };
>
>
> *Python*
>
> from pyqt_test import Foo, Emitter
>
> from PyQt5.QtCore import pyqtSlot
>
>
> @pyqtSlot(Foo)
>
> def pyslot(inst):
>
> print inst
>
>
> em = Emitter()
>
> em.itemAdded.connect(pyslot)
>
> em.AddItem()
>
> *Py output*
>
> <PyQt5.QtCore.QObject object at 0x000000000542B558>
>
>
>
> If I modify the example and use, for example, QFileSelector, instead of
> the
> Foo class then it gets passed along as a QFileSelector to the python
> slot.
> Leading me to believe I am missing some kind of directive or annotation
> in
> my sip files.
%ConvertToSubClassCode
Phil
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic