[Development] Why does QLabel::pixmap() return `const QPixmap*`?
Konstantin Ritt
ritt.ks at gmail.com
Sun Nov 30 20:11:42 CET 2014
Null pixmap actually means "no pixmap" (though there is a QPixmap instance,
with null pixmap data). Clearly, the API should be changed to QPixmap
QLabel::pixmap().
Regards,
Konstantin
2014-11-30 22:21 GMT+04:00 Yves Bailly <yves.bailly at laposte.net>:
> On 30/11/2014 09:35, Olivier Goffart wrote:
> > On Sunday 30 November 2014 06:37:11 Kevin Kofler wrote:
> >> Sze Howe Koh wrote:
> >>> I'm curious about the rationale behind this API design. I can't think
> >>> of any other Qt function that returns an implicitly-shared object by
> >>> pointer, so this seems inconsistent. e.g. QWidget::font() returns a
> >>> QFont by const-ref.
> >>
> >> Probably because the pointer can be null. C++ does not allow null
> >> references. (The compiler might let you get away with it, but in
> principle,
> >> it is not allowed.)
> >
> > That's not the reason because you can return a null pixmap
> (QPixmap::isNull).
>
> However a null pixmap and no pixmap at all are two different things :-)
>
> QPixmap const* pix = label->pixmap();
> if ( pix == nullptr )
> {
> // this label has no pixmap
> }
> else if ( pix->isNull() )
> {
> // this label does have a pixmap, which is null/empty
> }
> else
> {
> // etc.
> }
>
> Because of the different meanings, the API seems sensible to me.
>
> Regards,
>
> --
> (o< | Yves Bailly | -o)
> //\ | Linux Dijon : http://www.coagul.org | //\
> \_/ | | \_/`
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20141130/da61c655/attachment.html>
More information about the Development
mailing list