Short Version

I have a resource file :/doc/foo.pdf that I'd like to open using QDesktopServices on OS X, Windows, and LINUX. I've tried various flavors of specifying the URL, e.g.,

Qt Code:
  1. QUrl url;
  2. url.setScheme("qrc");
  3. url.setUrl(":/docs/foo.pdf");
  4. QDesktopServices::openUrl(url);
To copy to clipboard, switch view to plain text mode 

but nothing seems to work.

Q: Is it possible to use QDesktopServices to open a resource file and, if so, how?

LONG VERSION

The following works on OS X:

Qt Code:
  1. void MyClass::on_menuActionOpenManual_triggered()
  2. {
  3. QUrl url(directoryOf("doc").absoluteFilePath("foo.pdf"));
  4. url.setScheme("file");
  5. QDesktopServices::openUrl(url);
  6. }
To copy to clipboard, switch view to plain text mode 

where directoryOf() is defined as

Qt Code:
  1. QDir MyClass::directoryOf(const QString &subdir)
  2. {
  3. QDir dir(QApplication::applicationDirPath());
  4.  
  5. #if defined(Q_OS_WIN)
  6. if (dir.dirName().toLower() == "debug"
  7. || dir.dirName().toLower() == "release")
  8. dir.cdUp();
  9. #elif defined(Q_OS_MAC)
  10. if (dir.dirName() == "MacOS") {
  11. dir.cdUp();
  12. dir.cdUp();
  13. dir.cdUp();
  14. }
  15. #endif
  16. dir.cd(subdir);
  17. return dir;
  18. }
To copy to clipboard, switch view to plain text mode 

This code was taken out of a Qt book, which is available online at http://www.informit.com/articles/art...05554&seqNum=2

The idea is to find the proper path to the containing directory with a switch on platforms. This technique works on Mac OS X but fails on Windows. Note that the relative directory on OS X is ../../../doc/. This led me to believe there has to be an easier way to locate resources and (if so) would potentially alleviate the trouble in displaying the PDF file in Windows. And yes, the test machine on Windows has a PDF viewer associated with .pdf file extensions.