[PyQt] Problem using QObject created in C++ in Python
Pavol Mravec
palo at ksp.sk
Wed Dec 5 10:19:28 GMT 2007
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