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 assign an icon to a file type of a Qt program using the installscript file

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 4 Posters 6.0k 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.
  • T Offline
    T Offline
    tomy
    wrote on 21 Sept 2017, 16:48 last edited by tomy
    #1

    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?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tomy
      wrote on 22 Sept 2017, 13:53 last edited by
      #2

      No opinion!? :(

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JonB
        wrote on 23 Sept 2017, 08:31 last edited by JonB
        #3

        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().

        T 1 Reply Last reply 23 Sept 2017, 10:11
        2
        • J JonB
          23 Sept 2017, 08:31

          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().

          T Offline
          T Offline
          tomy
          wrote on 23 Sept 2017, 10:11 last edited by tomy
          #4

          @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

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JonB
            wrote on 23 Sept 2017, 10:20 last edited by JonB
            #5

            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....

            T 1 Reply Last reply 23 Sept 2017, 10:26
            1
            • J JonB
              23 Sept 2017, 10:20

              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....

              T Offline
              T Offline
              tomy
              wrote on 23 Sept 2017, 10:26 last edited by
              #6

              @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!

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tomy
                wrote on 23 Sept 2017, 10:32 last edited by
                #7

                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.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tomy
                  wrote on 23 Sept 2017, 10:50 last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    JonB
                    wrote on 23 Sept 2017, 10:50 last edited by JonB
                    #9

                    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:

                    • Google for "windows set file types icon". You'll have to read something like https://superuser.com/questions/301226/manually-change-filetype-icons-in-windows-7 or https://www.howtogeek.com/howto/12383/change-a-file-types-icon-in-windows-7/ or there's even a video at https://www.youtube.com/watch?v=tEer0_LjRQY. Looks like you'll either need to download a bit of freeware to do it nicely, or read up on how to do it directly in the Registry.
                    • Get your .sp associated with your .exe and get its icon assigned to whatever you want.
                    • Search registry for mentions of your .ico file and see what it put where.

                    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....

                    T 1 Reply Last reply 23 Sept 2017, 11:04
                    0
                    • J JonB
                      23 Sept 2017, 10:50

                      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:

                      • Google for "windows set file types icon". You'll have to read something like https://superuser.com/questions/301226/manually-change-filetype-icons-in-windows-7 or https://www.howtogeek.com/howto/12383/change-a-file-types-icon-in-windows-7/ or there's even a video at https://www.youtube.com/watch?v=tEer0_LjRQY. Looks like you'll either need to download a bit of freeware to do it nicely, or read up on how to do it directly in the Registry.
                      • Get your .sp associated with your .exe and get its icon assigned to whatever you want.
                      • Search registry for mentions of your .ico file and see what it put where.

                      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....

                      T Offline
                      T Offline
                      tomy
                      wrote on 23 Sept 2017, 11:04 last edited by tomy
                      #10

                      @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:

                      • Google for "windows set file types icon". You'll have to read something like https://superuser.com/questions/301226/manually-change-filetype-icons-in-windows-7. Looks like you'll either need to download a bit of freeware to do it nicely, or read up on how to do it directly in the Registry.

                      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.

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        JonB
                        wrote on 23 Sept 2017, 11:21 last edited by JonB
                        #11

                        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.)

                        1 Reply Last reply
                        2
                        • T Offline
                          T Offline
                          tomy
                          wrote on 23 Sept 2017, 19:15 last edited by tomy
                          #12

                          @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?

                          1 Reply Last reply
                          0
                          • T Offline
                            T Offline
                            tomy
                            wrote on 23 Sept 2017, 20:04 last edited by tomy
                            #13

                            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

                            jsulmJ 1 Reply Last reply 25 Sept 2017, 07:36
                            0
                            • T tomy
                              23 Sept 2017, 20:04

                              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

                              jsulmJ Online
                              jsulmJ Online
                              jsulm
                              Lifetime Qt Champion
                              wrote on 25 Sept 2017, 07:36 last edited by
                              #14

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

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              T 1 Reply Last reply 25 Sept 2017, 07:58
                              1
                              • jsulmJ jsulm
                                25 Sept 2017, 07:36

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

                                T Offline
                                T Offline
                                tomy
                                wrote on 25 Sept 2017, 07:58 last edited by
                                #15

                                @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.

                                jsulmJ 1 Reply Last reply 25 Sept 2017, 07:59
                                0
                                • T tomy
                                  25 Sept 2017, 07:58

                                  @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.

                                  jsulmJ Online
                                  jsulmJ Online
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on 25 Sept 2017, 07:59 last edited by
                                  #16

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

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  T 1 Reply Last reply 25 Sept 2017, 08:02
                                  0
                                  • jsulmJ jsulm
                                    25 Sept 2017, 07:59

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

                                    T Offline
                                    T Offline
                                    tomy
                                    wrote on 25 Sept 2017, 08:02 last edited by
                                    #17

                                    @jsulm

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

                                    Yes.
                                    0_1506326511035_Untitled.png

                                    Pranit PatilP 1 Reply Last reply 23 Jun 2018, 11:18
                                    0
                                    • T tomy
                                      25 Sept 2017, 08:02

                                      @jsulm

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

                                      Yes.
                                      0_1506326511035_Untitled.png

                                      Pranit PatilP Offline
                                      Pranit PatilP Offline
                                      Pranit Patil
                                      wrote on 23 Jun 2018, 11:18 last edited by
                                      #18

                                      @tomy Can you share full process bz im facing same problem.

                                      Thank You

                                      @Embedded Software Developer
                                      God has given you one face, and you make yourself another.

                                      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