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. Setting QT application .exe icon

Setting QT application .exe icon

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 516 Views 1 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.
  • H Offline
    H Offline
    he_R0
    wrote on last edited by he_R0
    #1

    I am having trouble figuring out why setting the .exe icon isn't working. I followed the documentation for setting the application icon https://doc.qt.io/qt-6/appicon.html. I created an .ico file containing 16x16,32x32,48x48 dimensions. I created the resource file IDI_ICON1 ICON "myappico.ico". I set it in my cmakelists file as

    if(WIN32)
    set(app_icon_resource_windows "${CMAKE_CURRENT_SOURCE_DIR}/app_icon.rc")
    endif()

    qt_add_executable(MyApp WIN32
    main.cpp
    ${app_icon_resource_windows}
    )

    It doesn't show the app icon when looking at it in build folders, or when creating shortcuts of the .exe file. I've tried deleting folders and rebuilding, it doesn't show. My .rc file is in the root directory and contains a path to the icon.ico (resources/icons/icon.ico) and my .rc file is IDI_ICON1 ICON "resources/icons/icons.ico". I debug using message(STATUS "Icon resource: ${app_icon_resource_windows}"), and it correctly shows it located the .rc file. What can be the issue? It also doesn't work when building in release mode. Thanks

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

      See if you can reproduce that error when building one of Qt's examples that uses .rc-files and icons, I'm thinking of C:\Qt\Examples\Qt-6.9.1\quick\window (it's called "Qt Quick Examples - Windows and Screen" in the Qt Creator Examples tab).

      Unfortunately it has fared rather badly in the conversion from qmake to CMake, it compiles and runs fine but without any app icon or details (in contrast to the qmake-based version from Qt 5)

      To get it back to display an app icon:
      toss the window.pro file (it's a vestige of Qt5) and
      add these lines to the CMakeLists.txt file:

      # add this one after add_subdirectory...
      set(app_icon_resource_windows "${CMAKE_CURRENT_SOURCE_DIR}/resources/window.rc")
      

      and change the qt_add_executable statement to

      qt_add_executable(windowexample
          WIN32
          main.cpp
          ${app_icon_resource_windows}
      )
      

      Rebuild and the windowexample.exe file should now exhibit the app icon (and if you hover the mouse over it, File Explorer should display "File description: QtQuck Window Example etc. in a tooltip)

      If that icon shows up, maybe you can use the CMakeLists.txt in the QtQuick Window example for your own project...

      H 1 Reply Last reply
      3
      • hskoglundH hskoglund

        See if you can reproduce that error when building one of Qt's examples that uses .rc-files and icons, I'm thinking of C:\Qt\Examples\Qt-6.9.1\quick\window (it's called "Qt Quick Examples - Windows and Screen" in the Qt Creator Examples tab).

        Unfortunately it has fared rather badly in the conversion from qmake to CMake, it compiles and runs fine but without any app icon or details (in contrast to the qmake-based version from Qt 5)

        To get it back to display an app icon:
        toss the window.pro file (it's a vestige of Qt5) and
        add these lines to the CMakeLists.txt file:

        # add this one after add_subdirectory...
        set(app_icon_resource_windows "${CMAKE_CURRENT_SOURCE_DIR}/resources/window.rc")
        

        and change the qt_add_executable statement to

        qt_add_executable(windowexample
            WIN32
            main.cpp
            ${app_icon_resource_windows}
        )
        

        Rebuild and the windowexample.exe file should now exhibit the app icon (and if you hover the mouse over it, File Explorer should display "File description: QtQuck Window Example etc. in a tooltip)

        If that icon shows up, maybe you can use the CMakeLists.txt in the QtQuick Window example for your own project...

        H Offline
        H Offline
        he_R0
        wrote on last edited by he_R0
        #3

        @hskoglund said in Setting QT application .exe icon:

        Unfortunately it has fared rather badly in the conversion from qmake to CMake, it compiles and runs fine but without any app icon or details (in contrast to the qmake-based version from Qt 5)

        I was able to reproduce the error. I realized I missed an important step in the documentation for setting the app icon in CMAKE:

        If you do not use qmake, the necessary steps are: first, create an .rc file and run the rc or windres program on the .rc file, then link your application with the resulting .res file.

        Works with

        target_sources(MyApp PRIVATE ${app_icon_resource_windows })

        1 Reply Last reply
        0
        • H he_R0 has marked this topic as solved on

        • Login

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