/ Comments off

I am creating a CMake file for compiling a simple hello world program that uses QtCore. I use CMake to generate a VS 2012 project and it compiles fine. But when I execute it, it gives an error that says that Qt5Core.dll is missing.

In order for findpackage to be successful, Qt 5 must be found below the CMAKEPREFIXPATH, or the Qt5DIR must be set in the CMake cache to the location of the Qt5WidgetsConfig.cmake file. The easiest way to use CMake is to set the CMAKEPREFIXPATH environment variable to the install prefix of Qt 5. Qt5usemodules(toview Core)@ Am I missing something? Is there a better way to do this? Thanks in advance! 1 Reply Last reply. Bjanuario last edited. Did you check your Qt environment path? 1 Reply Last reply. XxOsurfer3xX last edited.

I can fix this copying the .dll manually into the executable's directory, but I don't like this solution. Here is my CMake file:

set (CMAKE_PREFIX_PATH 'C:qt_srcqt5-2010qtbase')

Qt5_use_modules Cmake


add_executable(toview ${SOURCE})
qt5_use_modules(toview Core)@

Am I missing something? Is there a better way to do this? Thanks in advance!

CMake is a tool that helps simplify the build process for development projects across different platforms. CMake automates the generation of buildsystems such as Makefiles and Visual Studio project files.

CMake is a 3rd party tool with its own documentation. The rest of this topic details the specifics of how to use Qt 5 with CMake. The minimum version required to use Qt5 is CMake 3.1.0.

Getting Started

The first requirement when using CMake is to use find_package to locate the libraries and header files shipped with Qt. These libraries and header files can then be used to build libraries and applications based on Qt.

The recommended way to use Qt libraries and headers with CMake is to use the target_link_libraries command. This command automatically adds appropriate include directories, compile definitions, the position-independent-code flag, and links to the qtmain.lib library on Windows.

To build a helloworld GUI executable, typical usage would be:


In order for find_package to be successful, Qt 5 must be found below the CMAKE_PREFIX_PATH, or the Qt5_DIR must be set in the CMake cache to the location of the Qt5Config.cmake file. The easiest way to use CMake is to set the CMAKE_PREFIX_PATH environment variable to the install prefix of Qt 5.

Excel pay slip Template UK U.K based companies using that specific format after deduction of TAXES and other insurance. In addition, it is very important to use driver salary slip template excel, because of its efficient global use. For more types of format download, you can contact us and get custom template. Format for drivers salary slip. Regardless of which one is selected, the best kind of salary slip format is basic and professional in nature. Advertisements The first salary slip format: The first salary slip format is laid out horizontally, with the necessary information regarding the company in the top left hand corner. Jul 11, 2020 Salary Slip Format for Car Driver Uses of the Driver Salary Slip Template Excel: Salary slip is imperative for various purposes as it can be displayed as a confirmation to new managers that they have been paid that sum or proof of installment put forth in defense of any debate and so forth. Dec 27, 2019 Editable Word (docx) version of Driver salary/Payslip template/format Here is an editable word version of the driver salary slip which you can use this editable version if you wish to make any edits, or even pre-fill the vehicle, driver name, month, salary amount, etc. Finally, take a printout to get the driver and your signatures.

The CMAKE_AUTOMOC setting runs moc automatically when required. For more on this feature see the CMake AUTOMOC documentation

Imported targets

Imported targets are created for each Qt module. Imported target names should be preferred instead of using a variable like Qt5<Module>_LIBRARIES in CMake commands such as target_link_libraries. The actual path to the library can be obtained using the LOCATION property:

Note however that it is rare to require the full location to the library in CMake code. Most CMake APIs are aware of imported targets and can automatically use them instead of the full path.

Each module in Qt 5 has a library target with the naming convention Qt5::<Module> which can be used for this purpose.

Imported targets are created with the configurations Qt was configured with. That is, if Qt was configured with the -debug switch, an imported target with the configuration DEBUG will be created. If Qt was configured with the -release switch an imported target with the configuration RELEASE will be created. If Qt was configured with the -debug-and-release switch (the default on windows), then imported targets will be created with both RELEASE and DEBUG configurations.

If your project has custom CMake build configurations, it may be necessary to set a mapping from your custom configuration to either the debug or release Qt configuration.

Plugins are also available as IMPORTED targets in CMake. The Qt Network, Qt SQL, Qt GUI, and Qt Widgets modules have plugins associated. They provide a list of plugins in the Qt5<Module>_PLUGINS variable.

Variable Reference

Module variables

The result of a find_package call is that imported targets will be created for use with target_link_libraries, some variables will be populated with information required to configure the build, and macros will be made available for use. The name of the imported target for each module matches the name of the module with a prefix of 'Qt5::', for example Qt5::Widgets. All of the package-specific variables have a consistent name with a prefix of the name of the package. For example, find_package(Qt5 COMPONENTS Widgets) will make the following variables available if successfully found:

  • Qt5Widgets_VERSION String describing the version of the module.
  • Qt5Widgets_LIBRARIES List of libraries for use with the target_link_libraries command.
  • Qt5Widgets_INCLUDE_DIRS List of directories for use with the include_directories command.
  • Qt5Widgets_DEFINITIONS List of definitions for use with add_definitions.
  • Qt5Widgets_COMPILE_DEFINITIONS List of definitions for use with the COMPILE_DEFINITIONS target property.
  • Qt5Widgets_FOUND Boolean describing whether the module was found successfully.
  • Qt5Widgets_EXECUTABLE_COMPILE_FLAGS String of flags to be used when building executables.

Equivalents of those variables will be available for all packages found with a find_package call. Note that the variables are case-sensitive.

Installation variables

Additionally, several other variables are available which do not relate to a particular package, but to the Qt installation itself.

  • QT_VISIBILITY_AVAILABLE Boolean describing whether Qt was built with hidden visibility.
  • QT_LIBINFIX String containing the infix used in library names.

Using Cmake With QT 5 Learn Now From Your QT Experts KDAB

Macro Reference

Qt5Core macros

CMake Manual Qt 5.10

Macros available when Qt5Core is found.

qt5_wrap_cpp(outfiles inputfile .. OPTIONS ..)Create moc code from a list of files containing Qt class with the Q_OBJECT declaration. Per-directory preprocessor definitions are also added. Options may be given to moc, such as those found when executing 'moc -help'.
qt5_add_resources(outfiles inputfile .. OPTIONS ..)Create code from a list of Qt resource files. Options may be given to rcc, such as those found when executing 'rcc -help'.
qt5_add_binary_resources(target inputfile .. OPTIONS .. DESTINATION ..)Create an RCC file from a list of Qt resource files. Options may be given to rcc, such as those found when executing 'rcc -help'. A destination may be given to use a different filename or path for the RCC file.
qt5_generate_moc(inputfile outputfile )Creates a rule to run moc on infile and create outfile. Use this if for some reason QT5_WRAP_CPP() isn't appropriate, e.g. because you need a custom filename for the moc file or something similar.
qt5_use_modules(target [LINK_PUBLIC LINK_PRIVATE] module .. )Indicates that the target uses the named Qt 5 modules. The target will be linked to the specified modules, use the include directories installed by those modules, use the COMPILE_DEFINITIONS set by those modules, and use the COMPILE_FLAGS set by the modules. The LINK_PRIVATE or LINK_PUBLIC specifiers can optionally be specified. If LINK_PRIVATE is specified then the modules are not made part of the link interface of the target. See the documentation for target_link_libraries for more information.

Note that this macro is only available if using CMake 2.8.9 or later. This macro is obsolete. Use target_link_libraries with IMPORTED targets instead.

Qt5Widgets macros

Macros available when Qt5Widgets is found.

See All Results For This Question

qt5_wrap_ui(outfiles inputfile .. OPTIONS ..)Create code from a list of Qt designer ui files. Options may be given to uic, such as those found when executing 'uic -help'

Qt5DBus macros

Macros available when Qt5DBus is found.

qt5_add_dbus_interface(outfiles interface basename)Create the interface header and implementation files with the given basename from the given interface xml file and add it to the list of sources
qt5_add_dbus_interfaces(outfiles inputfile .. )Create the interface header and implementation files for all listed interface xml files the name will be automatically determined from the name of the xml file
qt5_add_dbus_adaptor(outfiles xmlfile parentheader parentclassname [basename] [classname])Create a dbus adaptor (header and implementation file) from the xml file describing the interface, and add it to the list of sources. The adaptor forwards the calls to a parent class, defined in parentheader and named parentclassname. The name of the generated files will be <basename>adaptor.{cpp,h} where basename defaults to the basename of the xml file. If <classname> is provided, then it will be used as the classname of the adaptor itself.
qt5_generate_dbus_interface( header [interfacename] OPTIONS ..)Generate the xml interface file from the given header. If the optional argument interfacename is omitted, the name of the interface file is constructed from the basename of the header with the suffix .xml appended. Options may be given to qdbuscpp2xml, such as those found when executing 'qdbuscpp2xml --help'

Qt5LinguistTools macros

Macros available when Qt5LinguistTools is found.

qt5_create_translation( qm_files directories .. sources .. ts_files .. OPTIONS ..)Out: qm_files In: Directories sources ts_files Options: flags to pass to lupdate, such as -extensions to specify Extensions for a directory scan. Generates commands to create .ts (via lupdate) and .qm (via lrelease) - files from directories and/or sources. The ts files are created and/or updated in the source tree (unless given with full paths). The qm files are generated in the build tree. Updating the translations can be done by adding the qm_files to the source list of your library/executable, so they are always updated, or by adding a custom target to control when they get updated/generated.
qt5_add_translation( qm_files ts_files .. )Out: qm_files In: ts_files Generates commands to create .qm from .ts - files. The generated filenames can be found in qm_files. The ts_files must exist and are not updated in any way.