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:
tr("Open Image"),
tr("Image Files (*.png *.tga *.bmp)"));
if (!fileName.isEmpty())
{
targetImage
= new QImage(fileName,
"PNG");
if(targetImage->isNull())
{
tr("Viewer"),
tr("Cannot load %1.").arg(fileName));
return;
}
onScreenImage.
setBackgroundRole(QPalette::Base);
onScreenImage.setScaledContents(true);
onScreenImage.
setPixmap(QPixmap::fromImage(*targetImage
));
}
}
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(*targetImage));
}
}
To copy to clipboard, switch view to plain text mode
What am I doing wrong?
Bookmarks