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

Pavol Mravec palo at ksp.sk
Wed Dec 5 12:28:39 GMT 2007


I found my bug. I needed to rebuild Qt, sip and PyQt in MS VC++. Now it works.

Pavol Mravec

On Dec 5, 2007 11:19 AM, Pavol Mravec <palo at ksp.sk> 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
>


More information about the PyQt mailing list