Parsing icon for applications issue



  • I want to get applications icon from the registry. The problem is that I'm getting only default application icon. How to get the actual application icon? Thanks.

    Screenshot:
    alt text

    Code:

       QStringList allLocalMachineX86Keys;
       QString displayIcon;
       QString iconFile;
       QIcon programIcon;
       QStringList displayIconSplitted;
       QString iconSplittedData;
       QFileIconProvider fileIconProvider;
       QString displayName;
    
    QSettings registryKeyLocalMachineX86("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", QSettings::NativeFormat);
            allLocalMachineX86Keys = registryKeyLocalMachineX86.allKeys();
    
            for (QString key : allLocalMachineX86Keys) {
                if (!key.isEmpty()) {
                    if (key.contains("DisplayIcon")) {
                        displayIcon = registryKeyLocalMachineX86.value(key).toString();
    
                        if (displayIcon.contains("\"")) {
                            displayIconSplitted = displayIcon.split("\"");
                            iconSplittedData = displayIconSplitted.value(displayIconSplitted.length() - 2);
                            iconFile = iconSplittedData;
                        } else if (displayIcon.contains(",")) {
                            displayIconSplitted = displayIcon.split(",");
                            iconSplittedData = displayIconSplitted.value(displayIconSplitted.length() - 2);
                            iconFile = iconSplittedData;
                        } else {
                            iconFile = displayIcon;
                        }
    
                        if (iconFile.contains(".ico")) {
                            programIcon = QIcon(iconFile);
                        } else {
                            QFileInfo fileInfo(iconFile);
                            programIcon = fileIconProvider.icon(fileInfo);
                        }
                    } else {
                        programIcon = QtWin::fromHICON(LoadIcon(NULL, IDI_APPLICATION));
                    }
    
                    if (key.contains("DisplayName") && registryKeyLocalMachineX86.value(key).toString() != "") {
                        displayName = registryKeyLocalMachineX86.value(key).toString();
                        emit appData(programIcon, displayName);
                    }
            }
       }
    


  • Update:
    When I have commented these lines of code:

    //else {
           //programIcon = QtWin::fromHICON(LoadIcon(NULL, IDI_APPLICATION));
         // }
    

    the apps icon displays but some are empty or not from the application (image below):
    alt text

    Anyone know how to fix it? Thanks in advance.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.