1) QPixmap::fromImage() is a static method --- it won't change the "pix" variable, but instead it returns a new QPixmap.
QPixmap pixmap = QPixmap::fromImage(image);
To copy to clipboard, switch view to plain text mode
2) And the label probably goes out of scope.
{
label.setPixmap(pixmap);
label.show();
} // label is a local variable and goes out of scope, so gets destructed according to normal C++ rules
{
QLabel label;
label.setPixmap(pixmap);
label.show();
} // label is a local variable and goes out of scope, so gets destructed according to normal C++ rules
To copy to clipboard, switch view to plain text mode
VS.
{
// label->setAttribute(Qt::WA_DeleteOnClose); // hint
label->setPixmap(pixmap);
label->show();
} // the pointer variable goes out of scope but the object itself remains alive
{
QLabel* label = new QLabel;
// label->setAttribute(Qt::WA_DeleteOnClose); // hint
label->setPixmap(pixmap);
label->show();
} // the pointer variable goes out of scope but the object itself remains alive
To copy to clipboard, switch view to plain text mode
Bookmarks