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 add a .qrc file to an executable with CMake
Forum Updated to NodeBB v4.3 + New Features

How to add a .qrc file to an executable with CMake

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 2.9k 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.
  • J Offline
    J Offline
    jkwok678
    wrote on 29 Aug 2021, 12:53 last edited by jkwok678
    #1

    How can I add the resources.qrc to the executable when the project is seperated by library and executable?
    As I have graphics that I want to display on the executable.

    cmake_minimum_required(VERSION 3.5)
    
    project(MyProject VERSION 0.1 LANGUAGES CXX)
    
    find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
    find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Gui Core)
    
    add_library(Mylib STATIC 
        map.cpp
        map.h
        window.cpp
        window.h
        )
    
    add_library(Mylib ::Mylib ALIAS Mylib )
    target_include_directories(Mylib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
    target_link_libraries(Mylib PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets)
    
    set_target_properties(Mylib PROPERTIES
        AUTOMOC ON
        AUTOUIC ON
        AUTORCC ON
        CXX_STANDARD 11
        CXX_STANDARD_REQUIRED ON
    )
    
    add_executable(MyProject main.cpp )
    
    target_link_libraries(MyProject PUBLIC MyLib::MyLib)
    set_target_properties(MyProject PROPERTIES
        WIN32_EXECUTABLE TRUE
        MACOSX_BUNDLE TRUE
        CXX_STANDARD 11
        CXX_STANDARD_REQUIRED ON
    )
    
    
    1 Reply Last reply
    0
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 29 Aug 2021, 13:26 last edited by
      #2

      See https://forum.qt.io/topic/91984/adding-qrc-icon-resource-to-a-cmake-qt-project/2

      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
      • V Offline
        V Offline
        VRonin
        wrote on 31 Aug 2021, 15:25 last edited by VRonin
        #3

        Just add the qrc to the list of sources:

        add_library(Mylib STATIC 
            map.cpp
            map.h
            window.cpp
            window.h
            resources.qrc
            )
        

        Since you set AUTORCC ON everything will be done automatically

        "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
        2

        1/3

        29 Aug 2021, 12:53

        • Login

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