[Development] Why does QLabel::pixmap() return `const QPixmap*`?
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
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
> >> it is not allowed.)
> > That's not the reason because you can return a null pixmap
> 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
> // etc.
> Because of the different meanings, the API seems sensible to me.
> (o< | Yves Bailly | -o)
> //\ | Linux Dijon : http://www.coagul.org | //\
> \_/ | | \_/`
> Development mailing list
> Development at qt-project.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Development