I'm trying to load a jpg from the resources but it fails every time. I'm checking that the file exists and can be opened, but it will not load into a pixmap. Any suggestions?

Here's the code snippet (not very subtle but each assert is a failure - it fails on line 17):
Qt Code:
  1. QString filename(":/data/test.jpg");
  2. QFileInfo fileInfo(filename);
  3. if (!(fileInfo.exists() && fileInfo.isFile() && fileInfo.isReadable()))
  4. Q_ASSERT(0);
  5. QFile file(filename);
  6. if (!file.open(QIODevice::ReadOnly))
  7. {
  8. QString err = file.errorString();
  9. Q_ASSERT(0);
  10. }
  11. else
  12. {
  13. file.close();
  14. }
  15. QPixmap picture(filename);
  16. if (picture.isNull())
  17. Q_ASSERT(0);
To copy to clipboard, switch view to plain text mode