[Qt-interest] Getting QVariant from QPixmap...and a strange operator!

Nikos Chantziaras realnc at arcor.de
Tue Jul 20 08:22:13 CEST 2010


On 07/20/2010 09:05 AM, Mandeep Sandhu wrote:
>> This is typecast operator overloading.  You cannot specify a return type
>
> Oh. Ok, I didn't know this.
>
>> and it's the same as the target type, in this case QVariant.  The above
>> gets called whenever a QPixmap is casted into a QVariant.
>
> Then this is wrong:
> ...
> return QVariant(*pix);
>
> It should be instead:
> ...
> return (QVariant)(*pix);
>
> Since the former looked like creating a new QVariant object passing it
> a QPixmap as an arg.

It doesn't matter whether it's an implicit or explicit cast.  The 
operator ensures that you can use a QPixmap wherever a QVariant is 
expected and the operator is called automatically.



More information about the Qt-interest-old mailing list