[PyKDE] QColorGroup

Johannes Sixt Johannes.Sixt at telecom.at
Sun Jan 16 22:48:28 GMT 2000


On Fri, 14 Jan 2000, you wrote:
>Pete Ware wrote:
>> 
>> Wow, it's because a QPalette puts the foreground as the first object:
>> 
>> class Q_EXPORT QColorGroup                              // color group class
>> {
>> public:
>>     ...
>> private:
>>     QColor fg_col;
>>     QColor bg_col;
>>     ...
>> };
>> 
>> QColorGroup  color_group;
>> 
>> "color_group" is the same memory location as the first element
>> color_group.fg_col.
>> 
>> --pete

Phil,

a remedy for this situation would be that sipMapCppToSelf looks at the
requested type even if it finds already a Python object for the pointer. Then
it could wrap up the pointer a second time (for situations like the above where
the new type is unrelated to the old type) or it could "upgrade" (or
"downcast") the wrapper object to a derived class if the new class is derived
from the existing type. The latter would help in situations like the one that I
reported long ago under the subject "QScrollView.viewport() wrapped up with
wrong type".

>Which implies that C++ creates a temporary copy of an object when it
>returns a reference to it (and it's re-using the same memory in this
>case).  But (to me anyway) that goes against what C++ references are for
>- I'd always assumed they were semantic sugar for pointers.  I am
>confused in my ignorance...looks like I'm going to have to go out an
>find a book.

As a C programmer you can view references as pointers very well. I prefer,
however, the more C++-ish point of view, where a reference is just an alias,
ie. a different name for an existing object. This is very much like in Python
where the variables are just names for existing objects, and you can have
different names for the same object. 
But unlike Python, C++ references can't be reseated - there's plainly no syntax
to do that.

-- Hannes




More information about the PyQt mailing list