I have the following code to get the icon associated with a file type, implemented for Windows :
#if defined(Q_OS_WIN)
#include <QFileInfo>
#include <QtWinExtras/QtWin>
QIcon IconFromFile(const QString& fileName)
{
QIcon qIcon;
HICON hIcon;
hIcon = ExtractIconW(NULL, (const WCHAR*)fileName.constData(), 0);
if(hIcon == NULL)
{
SHFILEINFO shfi;
DWORD dwFileAttributes;
memset(&shfi, 0, sizeof(shfi));
if(QFileInfo(fileName).isDir())
dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
else
dwFileAttributes = FILE_ATTRIBUTE_ARCHIVE;
SHGetFileInfoW((const WCHAR*)fileName.constData(),
dwFileAttributes,
&shfi,
sizeof(SHFILEINFO),
SHGFI_USEFILEATTRIBUTES | SHGFI_ICON | SHGFI_SMALLICON);
hIcon = shfi.hIcon;
}
if(hIcon != NULL)
{
#if (QT_VERSION_MAJOR == 4)
qIcon = QIcon(QPixmap::fromWinHICON(hIcon));
#else
qIcon = QtWin::fromHICON(hIcon);
#endif
DestroyIcon(hIcon);
}
return qIcon;
}
#elif defined(Q_OS_LINUX)
QIcon IconFromFile(const QString& fileName)
{
// TODO: Implementar en Linux
return QIcon();
}
#endif
I would like if anyone could give me suggestions on how to get the icon associated with a file type in Linux , I am using Linux Mint .