<div dir="ltr"><div>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?<br></div><div><br></div><div><div>Python 2.7, 64bit<br></div><div>Windows 7</div></div><div><br></div><div><div>Qt 5.4.1</div><div>PyQt 5.4.1</div><div>SIP 4.16.7</div></div><div><br></div><div><br></div><div>I tried to make a minimal repro case;<br></div><div><br></div><div><br></div><div><i><b><u>C++</u></b></i></div><div><div>class Foo : public QObject</div><div>{</div><div>    Q_OBJECT</div><div>public:</div><div>    explicit Foo(QObject* parent = 0) : QObject(parent) { }</div><div>    ~Foo() {};</div><div>};</div><div><br></div><div>class Emitter : public QObject</div><div>{</div><div>    Q_OBJECT</div><div>public:</div><div>    Emitter() {}</div><div>    ~Emitter() {}</div><div>    void AddItem() { emit itemAdded( new Foo ); }</div><div><br></div><div>Q_SIGNALS:</div><div>    void itemAdded(Foo*);</div><div>};</div></div><div><br></div><div><b><u>SIP</u></b></div><div><div style=""><div>%Module(name=pyqt_test, call_super_init=True)</div><div><br></div><div>%ModuleCode</div><div>#include <test.h></div><div>%End</div><div><br></div><div>%Import QtCore/QtCoremod.sip</div><div><br></div><div>class Foo : public QObject</div><div>{</div><div>%TypeHeaderCode</div><div>#include <test.h></div><div>%End</div><div>public:</div><div>    explicit Foo(QObject *parent /TransferThis/ = 0);</div><div>    ~Foo();</div><div>};</div><div><br></div><div>class Emitter : public QObject</div><div>{</div><div>%TypeHeaderCode</div><div>#include <test.h></div><div>%End</div><div>public:</div><div>    Emitter();</div><div>    virtual ~Emitter();</div><div>    void AddItem();</div><div><br></div><div>Q_SIGNALS:</div><div>    void itemAdded(Foo*);</div><div>};</div><div><br></div></div></div><div><br></div><div><b><u>Python</u></b></div><div><p style="margin:0px">from pyqt_test import Foo, Emitter</p><p style="margin:0px">from PyQt5.QtCore import pyqtSlot</p><p style="margin:0px"><br></p><p style="margin:0px">@pyqtSlot(Foo)</p><p style="margin:0px">def pyslot(inst):</p><p style="margin:0px">    print inst</p><p style="margin:0px"><br></p><p style="margin:0px">em = Emitter()</p><p style="margin:0px">em.itemAdded.connect(pyslot)</p><p style="margin:0px">em.AddItem()</p><div><br></div>
<p style="margin:0px"><b><u>Py output</u></b></p><p style="margin:0px"><PyQt5.QtCore.QObject object at 0x000000000542B558></p><p style="margin:0px"></p><p style="margin:0px"><br></p><p style="margin:0px"><b><br></b></p><p style="margin:0px">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.<br></p><p style="margin:0px"><br></p><p style="margin:0px">Any ideas?</p><p style="margin:0px"><br></p><p style="margin:0px">Cheers,</p><p style="margin:0px">Johan</p><p style="margin:0px"><br></p></div><div><b><u><br></u></b></div><div><br></div></div>