[Qt-interest] How to get an icon associated with a certain filetype using Qt?
Steven Doerfler
sgd-qt at lugaru.com
Fri Mar 26 20:31:07 CET 2010
On 3/26/2010 2:13 PM, Oliver.Knoll at comit.ch wrote:
> Nikos Chantziaras wrote on Friday, March 26, 2010 6:13 PM:
>
>> The best that can be done is query the OS using the native API.
>>
> You are right, that might actually work on Linux (Unix) in case you are running Gnome or KDE. Indeed they seem to associate MIME types with applications, see http://en.wikipedia.org/wiki/File_association - see also http://ubuntuforums.org/showthread.php?t=383040 - it mentions "sudo update-mime-database /usr/share/mime/", so it seems that's where the MIME associations are stored.
>
> But on Windows and Mac that would most likely not work, because as already mentioned Windows uses the file extension and Mac "type codes and creator codes".
On Windows, you can just look up the MIME type in the registry under
HKEY_CLASSES_ROOT\MIME\DataBase\Content Type. That maps MIME types to
file name extensions.
Then use SHGetFileInfo to get the icon for that extension.
For OS X, I think you can use the Launch Services API to get an icon,
given a MIME type.
Steven
More information about the Qt-interest-old
mailing list