Cobra91151
Cobra91151

Reputation: 650

Get default app icon on Windows

I want to get default application icon from QFileIconProvider but there are only:

enum QFileIconProvider::IconType

QFileIconProvider::Computer
QFileIconProvider::Desktop  
QFileIconProvider::Trashcan 
QFileIconProvider::Network  
QFileIconProvider::Drive    
QFileIconProvider::Folder   
QFileIconProvider::File

Screenshot:

enter image description here

I can navigate to some system executable file without icon to get this default icon using QFileIconProvider, but I think there should be another approach. How to get this icon? Thanks.

Update:

I have found the identifier of default app icon - IDI_APPLICATION. The problem now is how to convert it to QIcon or QString? I have tried QString::fromWCharArray(IDI_APPLICATION) and QString::fromStdWString(IDI_APPLICATION) but it doesn't work, the app crashes. How to convert it? Thanks.

Upvotes: 0

Views: 882

Answers (2)

Pavan Chandaka
Pavan Chandaka

Reputation: 12731

You can also get the default icon from the application object. (May work on all platforms.)

QApplication app = QApplication(argc, argv);
QIcon icon = app.windowIcon();

Documentation link: http://doc.qt.io/qt-5/qguiapplication.html#windowIcon-prop

the function is available in QGuiApplication.

The QApplication inherits QGuiApplication.

Upvotes: 0

Cobra91151
Cobra91151

Reputation: 650

I have found the solution.

Code:

QIcon icon = QtWin::fromHICON(LoadIcon(NULL, IDI_APPLICATION));

Now it works.

Upvotes: 1

Related Questions