PDA

View Full Version : Retrieving a file's icon



sbeltz
29th October 2007, 15:15
Hello,

Is there any way to retrieve the icon of a file given the file's pathname? In particular, I am attempting to retrieve an application's icon.

I have been able to do this for Windows using SHGetFileInfo(), but my application needs to be cross-platform and this (obviously) won't work for Mac or Linux.

I have also tried the following:

QString file = "C:\application.exe";
QFileInfo fileInfo( file );
QFileIconProvider fileIconProvider;
QIcon appIcon = fileIconProvider.icon( fileInfo );
However this always returns the system's default icon for folders and files rather than the file's specific icon.

Any suggestions or thoughts on how I could do this would be most appreciated.
(I'm using Qt 4.2.2)

Thanks

jpn
29th October 2007, 23:09
Notice a missing escape character:

QString file = "C:\\application.exe";

mchara
30th October 2007, 08:51
HI, following a topic - does anyone knows way to extract icons stored in dll's resources?

kernel_panic
30th October 2007, 08:54
http://msdn2.microsoft.com/en-us/library/ms648068.aspx
http://msdn2.microsoft.com/en-us/library/ms648069.aspx

jpn
30th October 2007, 08:58
And once you start converting HICON to QIcon/QPixmap, notice convertHIconToPixmap() in src/gui/image/qpixmap_win.cpp ;)

kernel_panic
30th October 2007, 09:06
yep forgot that.
i prefer this solution:
http://www.methylblue.com/blog/hicon-to-qpixmap/

mchara
30th October 2007, 09:15
Thanks, that answers all my questions in this topic.

jay
10th September 2008, 12:38
Dear all,

can anyone help me to save QIcon as an image file.

Thanks in advance.

mchara
10th September 2008, 13:35
I'm not sure, because recently i had no time for programming private project(i got enough at work), but as far as i remember, i have made some changes in qt imageformat plugin for ico format taken from kde sources.
Kde had writing to ico files method in qt3 but after migration to qt 4 only ico reading was ported and writing method was commented and i reworked it (using some other open software as reference(i don't remember its name now) so it saves ico files in current version(of course it's limited implementation and it doesn't support all possible formats)

http://downloads.sourceforge.net/grapheffectsenv/Green-MoreStandardFormats-src-0.5.0-pro.zip?modtime=1216108108&big_mirror=0

i hope it will work for you(i didn't tested in on any linux)
CU