Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get icon from any file?
Forum Updated to NodeBB v4.3 + New Features

How to get icon from any file?

Scheduled Pinned Locked Moved Solved General and Desktop
icon
3 Posts 2 Posters 2.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndrzejB
    wrote on last edited by
    #1
    QMimeDatabase mime_database;
    QIcon icon;
    QList<QMimeType> mime_types = mime_database.mimeTypesForFileName("file.txt");
    icon = QIcon::fromTheme(mime_types[0].iconName());
    if (icon.isNull())  qDebug() << "null";
    qDebug() << mime_types[0].iconName();
    

    1.This above not works (print : null "text-plain")
    2.How get icon of Exe file? (not mime but specified for file)

    1 Reply Last reply
    0
    • hskoglundH Online
      hskoglundH Online
      hskoglund
      wrote on last edited by
      #2

      Hi, for 2. there's an example here

      1 Reply Last reply
      3
      • A Offline
        A Offline
        AndrzejB
        wrote on last edited by AndrzejB
        #3

        2 works, thanks!
        But why 1 icon isNull() ?

        1. Is possible 1 and 2 under Linux? Linux has something like mime or/and Elf binaries can holds icons?

        Bad:

        QPixmap extractMime(const QString &sourceFile)
        {
            QMimeDatabase mime_database;
            const QString nativeName = QDir::toNativeSeparators(sourceFile);   
            QIcon icon;
            QList<QMimeType> mime_types = mime_database.mimeTypesForFileName(nativeName);
            icon = QIcon::fromTheme(mime_types[0].iconName());
            if (icon.isNull())  qDebug() << "null";
            qDebug() << mime_types[0].iconName();
            return icon.pixmap(16);
        }
        

        Maybe this work for Linux, but for Windows I need registers. Sample C# application https://www.codeproject.com/Articles/29137/Get-Registered-File-Types-and-Their-Associated-Ico

        for example:
        Computer\HKEY_CLASSES_ROOT.mp3 has
        OpenWithProgIds/WMP11.AssocFile.MP3

        Computer\HKEY_CLASSES_ROOT\WMP11.AssocFile.MP3 has DefaultIcon = %SystemRoot%\system32\wmploc.dll,-732
        wmploc.dll is resources and 732 index of icon?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved