简体   繁体   English

Qt5和CMAKE_AUTORCC

[英]Qt5 and CMAKE_AUTORCC

I am attempting to port an existing project using Qt to use cmake. 我正在尝试使用Qt移植现有项目以使用cmake。 The project has (a few) ui and (one) qrc files. 该项目有(几个) ui和(一个) qrc文件。 In the CMakeLists.txt, if I use: 在CMakeLists.txt中,如果我使用:

set(CMAKE_AUTOUIC ON)

and generate a Visual Studio (2015) project, it has a pre-build step, generating the sources from the ui files, and adding those generated files to the VS project. 并生成Visual Studio(2015)项目,它具有预构建步骤,从ui文件生成源,并将这些生成的文件添加到VS项目。 However, if I include the qrc file in the project sources, and then set: 但是,如果我在项目源中包含qrc文件,然后进行设置:

set(CMAKE_AUTORCC ON)

The generated project no longer has the pre-build step. 生成的项目不再具有预构建步骤。 It does contain the corresponding qrc.cpp file. 它确实包含相应的qrc.cpp文件。 However, when the project build, it fails because the file doesn't exist, and doesn't get generated. 但是,在项目构建时,它会失败,因为文件不存在,也不会生成。 I've also tried setting CMAKE_AUTORCC to OFF , and using QT5_ADD_RESOURCES . 我还尝试将CMAKE_AUTORCC设置为OFF ,并使用QT5_ADD_RESOURCES That doesn't remove the ui prebuild step, but doesn't add the qrc.cpp to the project. 这不会删除ui预构建步骤,但不会将qrc.cpp添加到项目中。

I'm using Qt 5.6.0 and cmake 3.5.2. 我正在使用Qt 5.6.0和cmake 3.5.2。

I realize it's been almost 4 months, but I ran into the same exact problem just now, and read through your question. 我意识到已经快四个月了,但是我刚才遇到了同样的问题,并仔细阅读了您的问题。 After looking through Qt doc on icons/qrc resource system, I have a working solution. 浏览了icon / qrc资源系统上的Qt文档后,我有了一个可行的解决方案。 I have all 3 settings in the same CMakeLists.txt file -- previously had the first two on: 我在同一个CMakeLists.txt文件中拥有所有3个设置-以前有前两个设置:

set (CMAKE_AUTOMOC ON)
set (CMAKE_AUTOUIC ON)
set (CMAKE_AUTORCC ON)

Then when you add your exe/dll, do thus: 然后,当您添加exe / dll时,请执行以下操作:

addlibrary (${myDLL} SHARED ${mySRC_LIST} ${myQRC_LIST})

where, you guessed it, the new list of files ${myQRC_LIST} contains the list of .qrc files. 您猜对了,文件${myQRC_LIST}的新列表包含.qrc文件的列表。 Voilà! 瞧! My first try I had this result, which is very rare! 我的第一次尝试就得到了这个结果,这是非常罕见的!

文件菜单和工具栏

Of course I could have combined my .qrc files into ${mySRC_LIST} as well, but I like to keep my lists homogeneous. 当然,我也可以将.qrc文件合并到${mySRC_LIST}中,但是我希望保持列表的${mySRC_LIST} Whatever you do, please read through Qt Resource Doc so that the icons get included properly. 无论您做什么,都请通读Qt Resource Doc,以便正确包含图标。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM