Qt resources files with CMake and AUTORCC

后端 未结 2 755
隐瞒了意图╮
隐瞒了意图╮ 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);
      }
    };
    

提交回复
热议问题