Pete Ware wrote:
>
> With 0.9, it appears that ColorGroup.foreground() (et. al.) are
> returning the result as a QColorGroup object instead of a QColor
> object. Following is some sample code and the error
>
> self.app = qt.QApplication (sys.argv)
> pallete = qt.QPalette (qt.blue)
> n = normal_group = pallete.normal ()
>
> print n, n.foreground, n.foreground ()
>
> my_group = qt.QColorGroup (n.foreground (),
> n.background (),
> n.light (),
> n.dark (),
> n.mid (),
> n.text (),
> n.background ())
>
> This is from the "print". Notice the last one is a QColorGroup
> instead of QColor.
>
> <qt.QColorGroup instance at faee0>
> <built-in method foreground of QColorGroup object at 261a98>
> <qt.QColorGroup instance at faee0>
>
> Looking at the code in sipQColorGroup.cpp:
>
> res = &((QColorGroup *)sipMapThisToCpp(sipThis,sipClass_QColorGroup)) ->
>QColorGroup::foreground();
> return sipMapCppToSelf(res,sipClass_QColor);
>
> although I don't know anything about sip to be able to comment. Is
> this a bug or my misunderstanding?
>
> Thanks,
> --pete
It's definately a bug. What's happening is that "res" has the same
value that was returned by the call to QPalette::normal() (which was a
QColorGroup). sipMapThisToCpp() sees this and returns the same
corresponding Python object rather than creating a new one (with a class
of QColor). So it's not that n.foreground() is returning an object of
the wrong class, it's that it is always returning n.
The root cause of this is that I am a C programmer, not a C++
programmer, and I obviously don't understand how C++ implements
references. The following is the C++ equivalent of the above code.
#include <stdio.h>
#include <qapplication.h>
#include <qpalette.h>
int main(int argc,char **argv)
{
QApplication *app = new QApplication(argc,argv);
QPalette *palette = new QPalette(blue);
const QColorGroup *n = &palette -> normal();
printf("n is %0lx\n",(long)n);
printf("n -> foreground() is %0lx\n",(long)&n -> foreground());
}
Can anybody tell me why the two values displayed are the same?
Thanks,
Phil