Search code examples
c++qtmime-types

Find out the mime type and associated applications with Qt


How can I find out a mime-type or content-type of a given file? I cannot use the suffix because the file could be renamed.

Possible additions would be categorizing them as jpg, gif, png and so on are image files and can be opened by editing applications, which has been set in the OS.

Thank you in advance.


Solution

  • What platform? On *nix, you should refer to how the program file does it, which is based on a few heuristics including checks of the first few bytes of a file (many file formats start with a fixed header, including many image formats).

    If you're on Windows, the *nix file command is probably still instructive, even if you can't reuse its code as directly. There may also be some better solution in the Windows APIs (I'm not a Windows programmer).