The Ultimate Qt Community site
Home News Forum Wiki Contest FAQ Links

Go Back   Qt Centre Forum > Qt > Qt Programming

Qt Programming General Qt programming issues.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 29th October 2007, 14:15
sbeltz sbeltz is offline
Beginner
 
Join Date: Oct 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Retrieving a file's icon

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:
Qt Code:
  1. QString file = "C:\application.exe";
  2. QFileInfo fileInfo( file );
  3. QFileIconProvider fileIconProvider;
  4. 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

Reply With Quote
  #2  
Old 29th October 2007, 22:09
jpn jpn is offline
Guru
 
Join Date: Feb 2006
Location: Tampere, Finland
Qt products used: Qt4
Qt platforms used: Unix/X11, Windows
Posts: 5,418
Thanks: 36
Thanked 1,214 Times in 1,164 Posts
Default Re: Retrieving a file's icon

Notice a missing escape character:
Qt Code:
  1. QString file = "C:\\application.exe";
__________________
J-P Nurmi
Reply With Quote
  #3  
Old 30th October 2007, 07:51
mchara mchara is offline
Intermediate user
 
Join Date: Sep 2007
Location: Szczecin, Poland
Qt products used: Qt4
Qt platforms used: Windows
Posts: 147
Thanks: 7
Thanked 8 Times in 8 Posts
Default Re: Retrieving a file's icon

HI, following a topic - does anyone knows way to extract icons stored in dll's resources?

Reply With Quote
  #4  
Old 30th October 2007, 07:54
kernel_panic's Avatar
kernel_panic kernel_panic is offline
Intermediate user
 
Join Date: Jan 2007
Location: Germany
Qt products used: Qt4
Qt platforms used: Unix/X11, Windows
Posts: 163
Thanks: 8
Thanked 6 Times in 6 Posts
Default Re: Retrieving a file's icon

http://msdn2.microsoft.com/en-us/library/ms648068.aspx
http://msdn2.microsoft.com/en-us/library/ms648069.aspx

Reply With Quote
The following user says thank you to kernel_panic for this useful post:
mchara (30th October 2007)
  #5  
Old 30th October 2007, 07:58
jpn jpn is offline
Guru
 
Join Date: Feb 2006
Location: Tampere, Finland
Qt products used: Qt4
Qt platforms used: Unix/X11, Windows
Posts: 5,418
Thanks: 36
Thanked 1,214 Times in 1,164 Posts
Default Re: Retrieving a file's icon

And once you start converting HICON to QIcon/QPixmap, notice convertHIconToPixmap() in src/gui/image/qpixmap_win.cpp
__________________
J-P Nurmi
Reply With Quote
The following user says thank you to jpn for this useful post:
mchara (30th October 2007)
  #6  
Old 30th October 2007, 08:06
kernel_panic's Avatar
kernel_panic kernel_panic is offline
Intermediate user
 
Join Date: Jan 2007
Location: Germany
Qt products used: Qt4
Qt platforms used: Unix/X11, Windows
Posts: 163
Thanks: 8
Thanked 6 Times in 6 Posts
Default Re: Retrieving a file's icon

yep forgot that.
i prefer this solution:
http://www.methylblue.com/blog/hicon-to-qpixmap/

Reply With Quote
  #7  
Old 30th October 2007, 08:15
mchara mchara is offline
Intermediate user
 
Join Date: Sep 2007
Location: Szczecin, Poland
Qt products used: Qt4
Qt platforms used: Windows
Posts: 147
Thanks: 7
Thanked 8 Times in 8 Posts
Default Re: Retrieving a file's icon

Thanks, that answers all my questions in this topic.

Reply With Quote
  #8  
Old 10th September 2008, 11:38
jay jay is offline
Novice
 
Join Date: Feb 2008
Qt products used: Qt4
Qt platforms used: Unix/X11, Windows
Posts: 16
Thanks: 3
Thanked 0 Times in 0 Posts
Default Re: Retrieving a file's icon

Dear all,

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

Thanks in advance.

Reply With Quote
  #9  
Old 10th September 2008, 12:35
mchara mchara is offline
Intermediate user
 
Join Date: Sep 2007
Location: Szczecin, Poland
Qt products used: Qt4
Qt platforms used: Windows
Posts: 147
Thanks: 7
Thanked 8 Times in 8 Posts
Default Re: Retrieving a file's icon

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/gra...8&big_mirror=0

i hope it will work for you(i didn't tested in on any linux)
CU
__________________
See GrEEn (Graphics Effects Environment)
http://sourceforge.net/project/platf...roup_id=232746
a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mac application and the Dock Icon sekelsenmat Qt Programming 3 26th September 2007 10:23
translation file issue (files not included in .ts with lupdate) BigDams Qt Programming 5 22nd September 2006 08:04
[Win32/VC++ 8.0] Strange problems with qrc_*.cpp files mloskot Installation and Deployment 6 6th March 2006 10:28


All times are GMT +1. The time now is 15:49.

Powered by vBulletin Version 3.7.1 Copyright ©2000 - 2008, Jelsoft Enterprises Ltd., vRewrite 1.5 SEOed URLs completed by Tech Help Forum and Chalo Na.
© 2006–2008 Qt Centre - The Ultimate Qt Community site
Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.