How to assign an icon to a file type of a Qt program using the installscript file



  • Hi guys,

    I've been said it's a simple issue, and I myself too think so because there are many Windows programs published daily to the marked all have that ability and a good part of that programs are based on C++ or created by Qt. This is also the most valuable forum on Qt.
    Here is the source file and I use Qt Installer Framework with this script file for making an installer:

    function Component(){ }
    
    Component.prototype.createOperations = function()
    {
       component.createOperations();
        if (installer.value("os") == "win")
          {
            var userProfile = installer.environmentVariable("USERPROFILE");
            installer.setValue("UserProfile", userProfile);
    
            component.addOperation("CreateShortcut", "@TargetDir@/Spreadsheet.exe",
            "@UserProfile@/Desktop/Spreadsheet.lnk" ,"workingDirectory=@TargetDir@",
            "iconPath=@TargetDir@/Spreadsheet.ico");
    
            component.addOperation("CreateShortcut", "@TargetDir@/QSpreadsheet.exe",
            "@TargetDir@/Spreadsheet.lnk" ,"workingDirectory=@TargetDir@",
            "iconPath=@TargetDir@/Spreadsheet.ico");
    
            component.addOperation("CreateShortcut", "@TargetDir@/Spreadsheet.exe",
            "@StartMenuDir@/Spreadsheet.lnk", "workingDirectory=@TargetDir@",
            "iconPath=@TargetDir@/Spreadsheet.ico");
    
            component.addOperation("RegisterFileType", "sp",
            "@TargetDir@\\Spreadsheet.exe \" %1\"", "Tomy Files", "application/Tomy",
            "@TargetDir@/Spreadsheet.ico", "ProgId=Spreadsheet.sp")
          }
     }
    

    I've been said using that script file and Qt Installer Framework I can have the job done. But when I make the installer this way, no icon will be set on the file type of the program.
    Does anybody know what the problem is please?



  • No opinion!? :(



  • I am no expert --- never used Qt installer stuff! However, I note the following in your code:

    • In your 2nd CreateShortcut your exe is QSpreadsheet.exe --- is that a typo?
    • In your RegisterFileType you specify @TargetDir@/Spreadsheet.ico with forward-slash. In an example like http://doc.qt.io/qtinstallerframework/qt-installer-framework-registerfileextension-example.html they use installer.environmentVariable("SystemRoot") + "\\notepad.exe", so clearly they are using Windows backslashes in the path. Does it make a difference if you change to that?
    • After running your installer and letting it do whatever it does/does not do, go look in actual Windows Registry to see what entry it has created for your RegisterFileType. Play with that till it works, bring back any alterations to your Qt Installer Script? At the end of the day, the Installer's RegisterFileType will only be a thin wrapper to Windows facilities for creating Registry Entry to do that, so get it working manually from Windows and see how that compares to what the Installer produces.
    • It's just possible that registering a file type might require Admin permission, I don't know. Do you run installer as Admin?

    P.S.
    You can also see what the Installer code will be doing from https://github.com/qtproject/installer-framework/blob/master/src/libs/installer/registerfiletypeoperation.cpp, function RegisterFileTypeOperation::performOperation().



  • @JNBarchan

    • After running your installer and letting it do whatever it does/does not do, go look in actual Windows Registry to see what entry it has created for your RegisterFileType.

    I changes those two but still no success.
    From the scriptfile there isn't clear what address of registery should be searched for existence of the .sp extension.
    Thanks.

    Edit:
    I found this:
    0_1506161668006_Capture.PNG



  • So the path stored in the Registry is C:\Users\Abbasi\Desktop\Spreadsheet.ico. That's a file actually located on your desktop. Is that really the path to your .ico file, 'coz it doesn't look right to me....



  • @JNBarchan

    So the path stored in the Registry is C:\Users\Abbasi\Desktop\Spreadsheet.ico. That's a file actually located on your desktop. Is that really the path to your .ico file, 'coz it doesn't like right to me....

    No.
    So I put that icon file on the desktop and installed the program using run as administrator.
    Still like before!



  • If you want I can send you the package directory folder plus the command needed for creating the installer and the .exe file to test on your system.



  • If anyone has installed Qt Installer Framework on their Windows system, please download the stuff from here and test the program on Windows please.



  • I am assuming your statement "But when I make the installer this way, no icon will be set on the file type of the program." you mean that you are not seeing the right icon on a .sp file, not the icons on the 3 shortcuts to your .exe ... right?

    If I were trying to solve this, I would go:

    For all I know, it might not be possible to associate a .ico file with a file type. Usually the way this is done is to embed the icon inside your .exe and set the icon by pointing into the .exe correctly. (That is what the example http://doc.qt.io/qtinstallerframework/qt-installer-framework-registerfileextension-example.html I mentioned does; I don't actually see other examples where an external .ico file is used. Actually see https://msdn.microsoft.com/en-us/library/windows/desktop/hh127427(v=vs.85).aspx too, which implies it should work for a .ico.) Like I said, I have never actually done this, I'm just pointing the way for you....



  • @JNBarchan

    I am assuming your statement "But when I make the installer this way, no icon will be set on the file type of the program." you mean that you are not seeing the right icon on a .sp file, not the icons on the 3 shortcuts to your .exe ... right?

    Yes. All three shortcuts have the icon set on themselves. By running them the program shows up.
    But on the files having the extension .sp, no icon is set.

    If I were trying to solve this, I would go:

    Please note that I thinking about the users for whom I will send the file to install it on their Windows machine. Setting the icon should be done in the process of installation.

    For all I know, it might not be possible to associate a .ico file with a file type.

    Please look at this:

    0_1506164527092_Capture.PNG

    Those two .docx and .xlsx have icons on themselves but the .sp file has no one it itself.



  • I am not suggesting that your end users will have to Google for or do the file type icon association themselves! I'm suggesting you need to do so, as a "test run", in order to know what you need/does/does not work from the Qt Installer!

    I do understand the screenshot you are showing. You could either search the Registry to see how that is done for .xslx file types (btw, I think you'll find the icons are embedded in the WORD.EXE application not an external .ico file, though that may not be relevant), or you could follow the steps I have suggested.

    At the end of the day, I suspect your problem is how to do it right under Windows, rather than anything specific to do with Qt Installer. (Though I did suggest you just try using \ instead of / in your CreateShortcut's iconPath specification, that a very quick that's might be worth a try.)



  • @JNBarchan

    is that a typo?
    with forward-slash

    I read Docs and a thread and modified the script file and tried to install the app many times but no success. This is the last modification:

    component.addElevatedOperation("RegisterFileType", "sp",
            "@TargetDir@/Spreadsheet.exe/" %1/"", "Abbasi Files", "application/Abbasi",
            "@DesktopDir@/Spreadsheet.ico", "ProgId=Spreadsheet.sp")
    

    Play with that till it works, bring back any alterations to your Qt Installer Script?

    What do you mean?

    get it working manually from Windows and see how that compares to what the Installer produces.

    I couldn't find a clear and not-difficult way to register a file type on registery to compare it with the path and values the installer makes.
    The installer creates a value in the path below:
    0_1506192442425_Capture.PNG

    RegisterFileTypeOperation::performOperation()
    Get your .sp associated with your .exe and get its icon assigned to whatever you want.

    I couldn't understand these well.

    You could either search the Registry to see how that is done for .xslx file types

    Here is that which is much more complicated than the one for .sp:

    0_1506194011224_Capture.PNG

    (Though I did suggest you just try using \ instead of / in your CreateShortcut's iconPath specification, that a very quick that's might be worth a try.)

    I did it, and test it many times. No success until now.

    Did you test it on your system?



  • Something new happened!
    I searched for .sp in the registery and deleted all of them there.
    Then installed the program and restarted the Windows. This is the result:

    0_1506196798659_Capture.PNG

    The icon is set on both files 1 & 2.

    I ran the app using that shortcut and opened the files using the Open button. They opened. => No changes on files. Good.

    Then opened the files (1 & 2) using double clicking and chosing the application to run and "unchecked" the button:
    Always use the selected program to open this kind of file.
    Again they were opened and no changes on icons. Good.

    This time I checked that button and ran the files again. And it's the outcome: :( :(

    0_1506197068032_2.PNG


  • Moderators

    @tomy You associated now this file type with your app. Does your app have an registered icon?



  • @jsulm

    You associated now this file type with your app. Does your app have an registered icon?

    I'm not sure what you mean by registered icon, but, the shortcut above the files 1 and 2 at the screenshot above has an icon on itself and when double clicked, it runs the application. I put the icon in the folder data of the package directory folder and using it the installer registered that icon for the program I think.


  • Moderators

    @tomy Is your app shown with an icon in Windows (start menu for example)?



  • @jsulm

    Is your app shown with an icon in Windows (start menu for example)?

    Yes.
    0_1506326511035_Untitled.png


Log in to reply
 

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