Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to set the application icon on Windows using cmake ?
Qt 6.12 LTS is out! See what's new in the release blog

How to set the application icon on Windows using cmake ?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 21.0k Views 3 Watching
  • 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.
  • Q Offline
    Q Offline
    QtVik
    wrote on last edited by
    #1

    Hello,
    I am trying to set the application icon using .rc file and ico for icon.
    But i need the correct cmake command to set the icon file to exe.

    .rc file contains as below:
    IDI_ICON1 ICON DISCARDABLE "appicon.ico"

    Following is what i have in my cmake file:

    SET(WINDOWS_RESOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/appicon.rc)
    QT5_ADD_RESOURCES(RESOURCE ${WINDOWS_RESOURCE_PATH})
    QT5_WRAP_CPP(SAMPLEAPP_HDRS_MOC ${SAMPLEAPP_HDRS_QT_MOC})
    ADD_EXECUTABLE(SampleApp ${SAMPLEAPP_SRCS} ${SAMPLEAPP_HDRS_MOC} ${WINDOWS_RESOURCE_PATH})

    But i am getting following error:
    Error 1 error : 'C:/SampleApp/appicon.rc' Line: 1 Column: 1 [Start tag expected.] C:\SampleApp\buildQt541_win64-trunk\CUSTOMBUILD

    Please let me know what am I doing wrong here.
    or Please share a sample code to do the same.

    Thank you.

    A 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Did you check that your file contains the correct white spaces ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • Q QtVik

        Hello,
        I am trying to set the application icon using .rc file and ico for icon.
        But i need the correct cmake command to set the icon file to exe.

        .rc file contains as below:
        IDI_ICON1 ICON DISCARDABLE "appicon.ico"

        Following is what i have in my cmake file:

        SET(WINDOWS_RESOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/appicon.rc)
        QT5_ADD_RESOURCES(RESOURCE ${WINDOWS_RESOURCE_PATH})
        QT5_WRAP_CPP(SAMPLEAPP_HDRS_MOC ${SAMPLEAPP_HDRS_QT_MOC})
        ADD_EXECUTABLE(SampleApp ${SAMPLEAPP_SRCS} ${SAMPLEAPP_HDRS_MOC} ${WINDOWS_RESOURCE_PATH})

        But i am getting following error:
        Error 1 error : 'C:/SampleApp/appicon.rc' Line: 1 Column: 1 [Start tag expected.] C:\SampleApp\buildQt541_win64-trunk\CUSTOMBUILD

        Please let me know what am I doing wrong here.
        or Please share a sample code to do the same.

        Thank you.

        A Offline
        A Offline
        ambershark
        wrote on last edited by
        #3

        @QtVik That's not how you add windows resources.

        qt5_add_resources() is for qrc files or Qt Resources.

        To add your rc to your exe, you just do:

        add_executable(${PROJECT_NAME} ${SRCS} project.rc)

        project.rc would be whatever you name your resource file.

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        1 Reply Last reply
        3
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @ambershark good catch ! I missed that one.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          2
          • SGaistS SGaist

            @ambershark good catch ! I missed that one.

            A Offline
            A Offline
            ambershark
            wrote on last edited by
            #5

            @SGaist Hah yea I did too at first then I double checked one of my projects to be sure before posting that. ;)

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              QtVik
              wrote on last edited by
              #6

              Dear @ambershark @SGaist ,

              Thank you so much for your answers.
              It really worked :)

              Pradeep KumarP 1 Reply Last reply
              2
              • Q QtVik

                Dear @ambershark @SGaist ,

                Thank you so much for your answers.
                It really worked :)

                Pradeep KumarP Offline
                Pradeep KumarP Offline
                Pradeep Kumar
                wrote on last edited by
                #7

                Hi @QtVik

                @SGaist , @ambershark thanks for the answer for using cmake.
                @QtVik can u mark as solved, so the others users can get the solution for the above mentioned post.

                Thanks,

                Pradeep Kumar
                Qt,QML Developer

                1 Reply Last reply
                3
                • Q Offline
                  Q Offline
                  QtVik
                  wrote on last edited by
                  #8

                  Hello @ambershark @SGaist ,
                  It worked fine on windows.
                  But I am unable to see the icon on Linux.
                  Is there any different trick to make it work on Linux ?

                  Hello @Pradeep-Kumar ,
                  Shall I mark this as solved after I receive answer on Linux issue?

                  A 1 Reply Last reply
                  0
                  • Q QtVik

                    Hello @ambershark @SGaist ,
                    It worked fine on windows.
                    But I am unable to see the icon on Linux.
                    Is there any different trick to make it work on Linux ?

                    Hello @Pradeep-Kumar ,
                    Shall I mark this as solved after I receive answer on Linux issue?

                    A Offline
                    A Offline
                    ambershark
                    wrote on last edited by
                    #9

                    @QtVik Well that's kind of a different question. Linux doesn't use rc files like windows does.

                    There are a few different things for setting icons in linux. There is the application icon that you set with a call to QApplication::setIcon or QWindow::setIcon.

                    Then there is the window manager icon. That depends on which desktop you want to support. Here is help on that http://doc.qt.io/qt-5/appicon.html.

                    But what I mostly do is just set it in the desktop entry file I use for my app.

                    I.e.

                    [Desktop Entry]
                    Name=My App
                    Type=Application
                    Exec=/path/to/my/app
                    Icon=/path/to/my/icon/file.png
                    Comment=My cool app
                    

                    That's like the linux equivalent of a shortcut in windows. It will set your icon for you.

                    My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                    1 Reply Last reply
                    2
                    • Q Offline
                      Q Offline
                      QtVik
                      wrote on last edited by
                      #10

                      Thank you so much @ambershark .
                      I was more concerned about the window manger Icon.
                      Will try it out.

                      1 Reply Last reply
                      1

                      • Login

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