Move QPixmap to QLabel
-
Could I move QPixmap into the QLabel?
I haven't found any member function which support
move semantics or some function could move the QPixmap into the QLabel
even in Qt5.The original solution of QLabel is copy the
QPixmap you pass into the function.If I haven't missed any fucntions Qt provided, what kind of
technical reason QLabel do not support move semantics
or just provide the users a simple function to send the resource into
the QLabel but not copy.Thanks a lot
-
@ QLabel label;
label.setPixmap(pixmap);@ -
Thanks, but this looks like copy
According to the declaration
setPixmap(QPixmap const &)
Const& wouldn't increase reference count
I don't think they will share the same resourceand the implementation looks more like copy than move
@
void QLabel::setPixmap(const QPixmap &pixmap)
{
Q_D(QLabel);
if (!d->pixmap || d->pixmap->cacheKey() != pixmap.cacheKey()) {
d->clearContents();
d->pixmap = new QPixmap(pixmap);
}if (d->pixmap->depth() == 1 && !d->pixmap->mask()) d->pixmap->setMask(*((QBitmap *)d->pixmap)); d->updateLabel();
}
@looks like the QLabel will create a brand new copy of the QPixmap
if the d->pixmap do not point to anything or they don't have the
same cacheKey.But the behavior I want is something like
@
QPixmap *temp = origin_pixmap;
origin_pixmap = new_pixmap;
temp->release()
@or
@
std::string A, B;
//.............
A = std::move(B);
@