[C++-sig] One object, many references

Eric Jardim ericjardim at gmail.com
Mon Jul 25 12:40:59 CEST 2005


Hi,

I have wrapped some classes of the Qt4 library and some funny things 
happend.

For example. The classic QObject class. You can create some QObjects, and 
say if they have a parent or not. Its parent is another QObject. (the memory 
addresses are ficticious):

>>> from Qt import QObject
>>> a = QObject(None) # have no parent
>>> b = QObject(a) # a is the parent
>>> a
<Qt.QObject at '0x00000001'>
>>> b
<Qt.QObject at '0x00000002'>
>>> print a.parent()
None
>>> print b.parent()
<Qt.QObject at '0x00000003'>

The funny is that it is another python object representing the same C++ 
object. If I do this (objectName is a property with setter and getter):
>>> a.objectName = QString('Eric')
>>> QString_to_str(print b.parent.objectName)
'Eric'

So it is the same object. Why does this happens? I have tried many 
combinations (but not all) of return value policies but lead to the same 
thing. Sometimes when the Python shell closes it segfaults.

Is this intended to be like this? How do I assure that the objects are the 
same? Overload the "==" operator?

Thanks in advance.

[Eric Jardim]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20050725/5f19d177/attachment.htm>


More information about the Cplusplus-sig mailing list