[PyQt] Problem using QObject created in C++ in Python

Phil Thompson phil at riverbankcomputing.co.uk
Wed Dec 5 11:06:35 GMT 2007


On Wednesday 05 December 2007, Pavol Mravec wrote:
> I want to use C++ object derived from QObject in Python but it does
> not work. Eveything Qt related does not work e.g. signals, setting
> parent, etc. Am I missing something, is there bug in sip.wrapinstance
> or is this not supported?
>
> I am using MS VC++ 2005 Express edition, 32bit Windows XP.
>
> relevant C++ code:
>
> class ParsedModel  : public QAbstractItemModel
> {
>     Q_OBJECT
>     ...
> };
>
> creating object:
>
> PyObject *createParsedModel(...)
> {
> ...
> pm=new ParsedModel();
> ret=PyLong_FromVoidPtr(pm);
> return ret;  // returning to python
> }
>
> Python code:
> >>> from PyQt4.QtCore import *
> >>> import sip
> >>> from myutils import *
> >>> import sys
> >>> app=QCoreApplication(sys.argv)
> >>> app
>
> <PyQt4.QtCore.QCoreApplication object at 0x00BD7540>
>
> >>> a=createParsedModel()
> >>> q=QObject()
> >>> w=sip.wrapinstance(a, QAbstractItemModel)
> >>> w
>
> <PyQt4.QtCore.QAbstractItemModel object at 0x00BD75D0>
>
> >>> q.setParent(w)
>
> QObject::setParent: Cannot set parent, new parent is in a different thread

Based on the above it should be Ok.

Phil


More information about the PyQt mailing list