Using a QImage
is necessary if you are processing images outside of your GUI thread. Also the loadFromData()
function looks like it is used for passing in a large array of bytes, not the name of the file.
Here is how I would do it with a QPixmap.
QPixmap pix;
bool loaded = pix.load("test.jpg");
if(loaded == false)
{
label->setText("Failed to load test.jpg from" + QDir::currentPath());
}
else
{
pix = pix.scaled(200, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation);
label->setPixmap(pix);
}
You may also want to replace 200 and 300 with label->width()
and label->height()
. Scaling a pixmap this way looks the best, but you can also just set the pixmap and then use label->setScaledContents(true)