1

i want to check, if a pdf-reader is installed. The idea was to use QDesktopServices::openUrl("path/test.pdf") and if its return "false" i know that no pdf-reader is installed. The problem is, that if a pdf-reader is installed, it opens the pdf. Can I "disable" that?

/edit: My solution:

QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.pdf\\OpenWithProgids", QSettings::NativeFormat);
 if (settings.allKeys().size() == 0) {...}
Cœur
  • 37,241
  • 25
  • 195
  • 267
knuut
  • 71
  • 7
  • What is pdf-reader? Adobe Acrobat reader? – vahancho Jan 28 '15 at 10:42
  • QDesktopServices::openURL() calls the standard program that you use for *.pdf files. So it can be AdobeAcrobat reader, but it can also be another program. – knuut Jan 28 '15 at 10:49

1 Answers1

1

Can I "disable" that?

Simple answer - no.

As QDesktopServices::openUrl asks the system to open the file with the associated program, you can't disable it via Qt.

While not recommended, you could disable this on a per-platform basis, but if you're going down that route, I suggest using each platform's own features to check if there is an application associated with the pdf data file.

On Windows, it's in stored in the registry, while OS X uses LaunchServices.

However, just because a file association doesn't exist, it doesn't mean that a suitable application isn't installed, for opening a pdf.

If you want to be able to display a pdf, you're probably better off handling that directly in your program. You can read about some options for that here.

Community
  • 1
  • 1
TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
  • 1
    Thanks! I now use the registry to solve the problem. I add my solution to my first post. – knuut Jan 28 '15 at 15:33