Comments embedded:
Quote Originally Posted by SaldaVonSchwartz View Post
Qt Code:
  1. QString fileName = QFileDialog::getOpenFileName(this,
  2. tr("Open Image"),
  3. QDir::homePath(),
  4. tr("Image Files (*.png *.tga *.bmp)"));
  5. // you could have a BMP or Targa file at this point
  6. // Qt has no Targa format support out of the box
  7. if (!fileName.isEmpty())
  8. {
  9. targetImage = new QImage(fileName, "PNG");
  10. // Not much good if the file is not a PNG
  11. // You allocate memory you do not free: memory leak
  12. // No need for this to be on the heap at all
  13.  
  14. if(targetImage->isNull())
  15. {
  16. QMessageBox::information(this,
  17. tr("Viewer"),
  18. tr("Cannot load %1.").arg(fileName));
  19. return;
  20. }
  21.  
  22. onScreenImage.setBackgroundRole(QPalette::Base);
  23. onScreenImage.setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
  24. onScreenImage.setScaledContents(true);
  25. onScreenImage.setPixmap(QPixmap::fromImage(*targetImage));
  26. // Why did you use a QImage if you require a QPixmap ultimately?
  27. }
  28. }
To copy to clipboard, switch view to plain text mode 
You don't say if it is failing in the development or deployed environment. None of this will work deployed unless you also deploy the necessary imageformat plugins. What does QImageReader::supportedImageFormats() return?