Qt resources files with CMake and AUTORCC

后端 未结 2 754
隐瞒了意图╮
隐瞒了意图╮ 2021-02-02 13:11

Solution:

Add resource files in the add_executable() statement

Problem

(not in the add_library())

Fa

相关标签:
2条回答
  • 2021-02-02 13:46

    I'm not sure if this is new or not, but I have figured out a way to add resources to libraries.

    In my library's CMakeLists.txt I have the following:

    list (APPEND RESOURCES library.qrc)
    qt5_add_resources (RCC_SOURCES ${RESOURCES})
    
    ...
    
    add_library(library ${RCC_SOURCES} ${SOURCES})
    

    In the library, in one of my "main classes" (for me, this class was the first thing that gets created in the library and the last thing that gets destroyed), I did the following:

    class libClass : public QMainWindow {
      Q_OBJECT
    
    public:
      libClass() : QMainWindow(nullptr, 0) {
        Q_INIT_RESOURCE(library);
      }
    
      ~libClass() {
        Q_CLEANUP_RESOURCE(library);
      }
    };
    
    0 讨论(0)
  • 2021-02-02 14:03

    I think you need to link qrc_resources generated file.

    I suppose you know the next info:

    http://www.cmake.org/cmake/help/v3.0/manual/cmake-qt.7.html

    Where you can see the next line:

    add_executable(myexe main.cpp resource_file.qrc)
    

    More info:

    http://www.cmake.org/cmake/help/v3.0/prop_tgt/AUTORCC.html

    0 讨论(0)
提交回复
热议问题