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.
According to the declaration
setPixmap(QPixmap const &)
Const& wouldn’t increase reference count(any mistake?)
I don’t think they will share the same resource
and the implementation looks more like copy than move(Qt4.8.3)
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);
Pixmap implements Copy On Write concept, so copying a pixmap is not a heavy operation and actual data copy will happen only if you try to modify the original pixmap.