[PyKDE] parent method of QObject

Gey-Hong Gweon gweon at umich.edu
Mon Feb 21 22:46:07 GMT 2000


I am enjoying sip/PyQt/PyKDE very much. I am now trying to upgrade my
program to be usable with version 0.10. With version 0.9, I had several
problems: e.g., ColorGroup.foreground () didn't work, and QColor.pixel
() always returned 0 no matter what the color was. These problems seemed
to be gone now. Another reason that I did not want to stay with 0.9 was
that the source file for 0.9 was not available anymore! Occasionaly I
felt the need to look at the source file because I am often wrapping my
own C++ code with sip, and because I also would like to go to the source
code when I have some problem. Anyway, I am encountering an unexpected
problem with version 0.10. The following simple example illustrates the
problem.

## code 

from qt import *
 
app = QApplication ([])
 
p = QObject ()
c = QObject (p)
print p, [c]
print c.parent (), p.children ()
 
p = QFrame ()
c = QLineEdit (p)
c.setText ("I am here.")
print p, [c]
print c.parent (), p.children ()
print p.children () [0].text () 

## output (Qt-0.9)
<qt.QObject instance at 80c00d0> [<qt.QObject instance at 811ebd8>]
<qt.QObject instance at 80c00d0> [<qt.QObject instance at 811ebd8>]
<qt.QFrame instance at 811edf8> [<qt.QLineEdit instance at 80c00d0>]
<qt.QFrame instance at 811edf8> [<qt.QLineEdit instance at 80c00d0>]
I am here.

## output (Qt-0.10.1)
<qt.QObject instance at 80c00d0> [<qt.QObject instance at 8120448>]
<qt.QObject instance at 80c00d0> [<qt.QObject instance at 8120448>]
<qt.QFrame instance at 8120660> [<qt.QLineEdit instance at 80c00d0>]
<qt.QObject instance at 8121bd8> [<qt.QObject instance at 8122af8>]
Traceback (innermost last):
  File "/tmp/bug.py", line 15, in ?
    print p.children () [0].text ()
AttributeError: text

It seems to me that the return pointer of parent() is pointing to a
different address than the real parent, when the parent is an object of
a derived class of QObject, not a direct instance of QObject. (A simlar
situation is observed for parentWidget() which returns QWidget.) Is this
an intended feature or a bug?  How can I get the "real parent" with the
correct type? Of course, I can easily find a work-around using python,
but it is not very neat.

This problem occured both in the binary rpm version and in the version
compiled from source.
-- 
Gey-Hong Gweon
The University of Michigan, Physics Department, Ann Arbor, MI 48109
(734) 647-9434 (Office), 763-3417 (Lab), 763-9694 (Fax) 




More information about the PyQt mailing list