SaldaVonSchwartz
11th April 2012, 10:17
I'm on Windows7 and using Qt SDK 4.8.
Trying to read a file in with QImage but it just doesn't seem to load. That is, QImage(filename) or QImage(filename, "PNG") or QImage.load(filename) always return NULL.
Here's my code:
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"),
QDir::homePath(),
tr("Image Files (*.png *.tga *.bmp)"));
if (!fileName.isEmpty())
{
targetImage = new QImage(fileName, "PNG");
if(targetImage->isNull())
{
QMessageBox::information(this,
tr("Viewer"),
tr("Cannot load %1.").arg(fileName));
return;
}
onScreenImage.setBackgroundRole(QPalette::Base);
onScreenImage.setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
onScreenImage.setScaledContents(true);
onScreenImage.setPixmap(QPixmap::fromImage(*target Image));
}
}
What am I doing wrong?
Trying to read a file in with QImage but it just doesn't seem to load. That is, QImage(filename) or QImage(filename, "PNG") or QImage.load(filename) always return NULL.
Here's my code:
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"),
QDir::homePath(),
tr("Image Files (*.png *.tga *.bmp)"));
if (!fileName.isEmpty())
{
targetImage = new QImage(fileName, "PNG");
if(targetImage->isNull())
{
QMessageBox::information(this,
tr("Viewer"),
tr("Cannot load %1.").arg(fileName));
return;
}
onScreenImage.setBackgroundRole(QPalette::Base);
onScreenImage.setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
onScreenImage.setScaledContents(true);
onScreenImage.setPixmap(QPixmap::fromImage(*target Image));
}
}
What am I doing wrong?