0
votes

I have a Visual Studio 2017 project that is built with QT and VTK using CMake. I need to use image resources, and wish to use QT's .qrc resource system.

Information on this seems rare and complex when not using a QT project file. I have found this:

  1. Create a .qrc file that contains a list of the resources you would like to include

  2. Create a custom build step that invokes rcc on that file (documentation)

  3. Compile and link the resulting cpp source file into your program.

How to use Qt resource files in Visual Studio without a Qt project?

I am just completely confused right now on what the proper way to go about this is, and this is not enough information.

1
All three points you mentioned are correct. Which one you failed to perform? - vahancho

1 Answers

4
votes

Add this to your CMake:

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

This will run moc and rcc compiler automatically.

Then use the following to add the resources and link them

# Compiles binary resources into source code and puts the names into RESOURCES variable
qt5_add_resources(RESOURCES example.qrc)

# Adds the RESOURCES source code to your application so it will be linked
# and part of your executable
add_executable(exampleApplication main.cpp ${RESOURCES})

Further reading: