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. Adding qrc icon resource to a CMake Qt project
Forum Updated to NodeBB v4.3 + New Features

Adding qrc icon resource to a CMake Qt project

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 4 Posters 16.9k 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.
  • S Offline
    S Offline
    Slei
    wrote on 25 Jun 2018, 13:02 last edited by Slei
    #1

    Hey,

    I'm currently trying to add a icon to my cmake project, to be able to use it as SystemTrayIcon,
    it works fine when using qmake via

    Hierarchy:
    
    resources.qrc
       /icons
             myicon.ico
    
    .pro
    RESOURCES += \
        resource.qrc
    
    icon code: 
     auto icon = QIcon(":/icons/myicon.ico");
    

    but it doesn't work with cmake using the following cmake commands:

    qt5_add_resources(resource.qrc)
    
    

    or

    
    add_executeable(resource.qrc)
    

    has anyone any idea what i'm doing wrong?

    thanks

    ~slei

    1 Reply Last reply
    0
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 25 Jun 2018, 17:13 last edited by
      #2

      @Slei said in Adding qrc icon resource to a CMake Qt project:

      qt5_add_resources(resource.qrc)

      It must be qt5_add_resources(srcs_for_exe resource.qrc) and then later add_executable(... ${srcs_for_exe})
      See http://doc.qt.io/qt-5/cmake-manual.html#macro-reference

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • S Offline
        S Offline
        Slei
        wrote on 26 Jun 2018, 15:04 last edited by
        #3

        ok it generated a resource .cpp now with all the icon data, which seems to be good. bit it still doen't display an icon in the systemtray so something else might be wrong

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 26 Jun 2018, 15:14 last edited by
          #4

          Hi,

          Did you ensure that the generated cpp file gets compiled and linked properly ?

          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
          0
          • S Offline
            S Offline
            Slei
            wrote on 27 Jun 2018, 05:38 last edited by
            #5

            do I have to do anything special with cmake or should this be done automatically with one of those

            	set(CMAKE_AUTOMOC ON)
            	set(CMAKE_AUTORCC ON)
            	set(CMAKE_AUTOUIC ON)
            
            1 Reply Last reply
            2
            • S Offline
              S Offline
              Slei
              wrote on 27 Jun 2018, 09:40 last edited by Slei
              #6

              i probably should add that I'm currently using a source build, maybe the there is no .ico support by default?
              but I've alos tried it with png and jpg

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 27 Jun 2018, 16:36 last edited by
                #7

                Can you show your CMakeList.txt file ?

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

                S 1 Reply Last reply 10 Jul 2018, 14:13
                0
                • S Offline
                  S Offline
                  Slei
                  wrote on 10 Jul 2018, 13:51 last edited by Slei 7 Oct 2018, 13:52
                  #8
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • S SGaist
                    27 Jun 2018, 16:36

                    Can you show your CMakeList.txt file ?

                    S Offline
                    S Offline
                    Slei
                    wrote on 10 Jul 2018, 14:13 last edited by
                    #9

                    @SGaist said in Adding qrc icon resource to a CMake Qt project:

                    Can you show your CMakeList.txt file ?

                    I've tried it with GLOB for qrc or directly adding a qrc to the executable (custom cmake function in my case)

                    /       file(GLOB source_files *.c *.cpp *.qrc)
                           file(GLOB header_files *.h *.hpp *.txt)
                    
                    	set(CMAKE_INCLUDE_CURRENT_DIR ON)
                    	set(CMAKE_AUTOMOC ON)
                    	set(CMAKE_AUTORCC ON)
                    	set(CMAKE_AUTOUIC ON)
                    	find_package(Qt5Widgets REQUIRED)
                    	find_package(Qt5WebEngineWidgets REQUIRED)
                    	find_package(Qt5WebChannel REQUIRED)
                    
                    
                    	qt5_add_resources(COLYOO_QT_RESOURCES app.qrc web.qrc)
                    
                    	message(STATUS "SLEIDEBUG:${COLYOO_QT_RESOURCES}")
                    
                    
                           # add the GUI WIN32 executable
                           cyo_add_executable(${PROJECT_NAME} WIN32 ${source_files} ${header_files} chatwidget.ui ${COLYOO_QT_RESOURCES})
                    
                    1 Reply Last reply
                    0
                    • VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on 10 Jul 2018, 14:17 last edited by VRonin 7 Oct 2018, 14:17
                      #10

                      if you have set(CMAKE_AUTORCC ON) then there's no need to call qt5_add_resources just add your .qrc files to the list of sources for the target as they were .cpp files

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      S 2 Replies Last reply 10 Jul 2018, 15:08
                      2
                      • VRoninV VRonin
                        10 Jul 2018, 14:17

                        if you have set(CMAKE_AUTORCC ON) then there's no need to call qt5_add_resources just add your .qrc files to the list of sources for the target as they were .cpp files

                        S Offline
                        S Offline
                        Slei
                        wrote on 10 Jul 2018, 15:08 last edited by
                        #11

                        @VRonin

                        I've heard about that but it still doesn't work :o

                        1 Reply Last reply
                        0
                        • VRoninV VRonin
                          10 Jul 2018, 14:17

                          if you have set(CMAKE_AUTORCC ON) then there's no need to call qt5_add_resources just add your .qrc files to the list of sources for the target as they were .cpp files

                          S Offline
                          S Offline
                          Slei
                          wrote on 10 Jul 2018, 15:11 last edited by Slei 7 Oct 2018, 15:12
                          #12

                          @VRonin do I still have to add it to the executable and GLOB it then? or is this also done automatically with the AUTORCC

                          1 Reply Last reply
                          0
                          • VRoninV Offline
                            VRoninV Offline
                            VRonin
                            wrote on 10 Jul 2018, 15:15 last edited by
                            #13

                            you don't have to GLOB it, you can GLOB it. You could also add .qrc files in the same way you are adding chatwidget.ui at the moment

                            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                            ~Napoleon Bonaparte

                            On a crusade to banish setIndexWidget() from the holy land of Qt

                            1 Reply Last reply
                            1
                            • S Offline
                              S Offline
                              Slei
                              wrote on 10 Jul 2018, 15:32 last edited by
                              #14

                              @Slei said in Adding qrc icon resource to a CMake Qt project:

                              COLYOO_QT_RESOURCES

                              ok i think it works now, for whatever reason I'll test it a few times to be 100% sure, thsi is my current cmakelists.txt

                                  # search all source and header files
                                  file(GLOB source_files *.c *.cpp *.qrc)
                                  file(GLOB header_files *.h *.hpp *.txt)
                              
                              	set(CMAKE_INCLUDE_CURRENT_DIR ON)
                              	set(CMAKE_AUTOMOC ON)
                              	set(CMAKE_AUTORCC ON)
                              	set(CMAKE_AUTOUIC ON)
                              	find_package(Qt5Widgets REQUIRED)
                              	find_package(Qt5WebEngineWidgets REQUIRED)
                              	find_package(Qt5WebChannel REQUIRED)
                              
                              
                              	#qt5_add_resources(COLYOO_QT_RESOURCES app.qrc web.qrc)
                              
                              	message(STATUS "SLEIDEBUG:${COLYOO_QT_RESOURCES}")
                              
                              
                                  # add the GUI WIN32 executable
                                  cyo_add_executable(${PROJECT_NAME} WIN32 ${source_files} ${header_files} chatwidget.ui ${COLYOO_QT_RESOURCES})
                              

                              but i think i tried this version once before and it didn't work lol ._.

                              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