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:

Qt Code:
  1. QString fileName = QFileDialog::getOpenFileName(this,
  2. tr("Open Image"),
  3. QDir::homePath(),
  4. tr("Image Files (*.png *.tga *.bmp)"));
  5.  
  6. if (!fileName.isEmpty())
  7. {
  8. targetImage = new QImage(fileName, "PNG");
  9. if(targetImage->isNull())
  10. {
  11. QMessageBox::information(this,
  12. tr("Viewer"),
  13. tr("Cannot load %1.").arg(fileName));
  14. return;
  15. }
  16.  
  17. onScreenImage.setBackgroundRole(QPalette::Base);
  18. onScreenImage.setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
  19. onScreenImage.setScaledContents(true);
  20. onScreenImage.setPixmap(QPixmap::fromImage(*targetImage));
  21. }
  22. }
To copy to clipboard, switch view to plain text mode 

What am I doing wrong?