A pure Qmake project can't be imported in CLion directly. However, when converted into CMake, it can be opened and managed as a regular CMake application.
CMake-based Qt projects
For CMake version 3.0 and newer, Qt ships the modules that let CMake find and use Qt4 and Qt5 libraries. Take the following steps to configure CMakeLists.txt for your Qt project.
CMakeLists.txt for a Qt project
find_packagecommand to locate the required libraries and header files. For example:find_package(Qt5Widgets REQUIRED)
target_link_librariesto make your target dependent on these libraries and headers:target_link_libraries(helloworld Qt5::Widgets)
find_packageto perform successfully, CMake should be instructed on where to find the Qt installation.
One of the ways to do this is by setting the
CMAKE_PREFIX_PATHvariable. You can either pass it via
-Din the CMake settings dialog or via the
For example, in the case of MinGW on Windows:set(CMAKE_PREFIX_PATH "C:\\Qt\\Qt5.14.0\\5.14.0\\mingw73_32\\")
- set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON)
List all the .ui and .qrc files in the
add_executable()command along with your .cpp sources:add_executable( helloworld main.cpp mainwindow.cpp application.qrc )
Below you can find the full CMakeLists.txt script for a simple "Hello, world" application:
Setting up a Qt project in CLion
Toolchains on Windows
When installing Qt on Windows, pick the distributive that matches the environment you are using in CLion, MinGW or MSVC.
For MinGW, both the version and the bitness (32-bit MinGW or MinGW-w64) should match with your toolchain setup.
In CLion, go to(Ctrl+Alt+S), navigate to and select the toolchain that matches your Qt installation.
If you have several Qt installations, make sure to select the same toolchain as the one you specified in
As an example, in the case of MinGW:
Qt projects are handled as regular CMake projects in CLion, so you can configure CMake settings inas necessary.
In this dialog, you can also specify CMake options, such as
CMAKE_PREFIX_PATHinstead of setting them in CMakeLists.txt:
You can use Qt type renderers in CLion, however, for now, you need to set them manually either using the gdbinit/lldbinit scripts or, in the case of MSVC, via native visualizers.
CLion’s debugger for the MSVC toolchain can employ native visualizers if you have them in your project. Make sure to set the Enable NatVis renderers for LLDB option in .
For example, try copying qt5.natvis under your project root - CLion will detect and use it automatically.
Windows MinGW / macOS / Linux
For non-MSVC toolchains, a solution would be to configure the Qt renderers via .gdbinit/.lldbinit. These scripts are loaded on every invocation of GDB or LLDB, respectively. Try KDevelop formatters for GDB, KDevelop formatters for LLDB, or Lekensteyn's qt5printers (GDB).
Editing UI files in Qt Designer
By default, CLion opens .ui files in the editor. You can change this behavior in order to edit .ui files right in Qt Designer.
Go to Recognized File Types list, and delete the associated file extension., select Qt UI Designer Form from the
Next time you click a .ui file for opening, set the Open in associated application checkbox, and the files of this type will always open in Qt Designer.
If you get the Process finished with exit code -1073741515 (0xC0000135) error message when running on MinGW, the issue might relate to Qt deployment on Windows: dynamic libraries and Qt plugins must be found from the directory of the running binary. One of the possible workarounds is described below.
Copy the .dll-s located in bin under the MinGW directory in the Qt installation to your project’s generation folder, which is cmake-build-debug or cmake-build-release by default.
The libraries you will most likely need are libstdc++-6.dll, Qt5Widgets.dll, Qt5Gui.dll, and Qt5Core.dll, but your setup might require other libraries as well.
In the settings of the configuration you use for running, set the
QT_QPA_PLATFORM_PLUGIN_PATHenvironment variable to plugins\platforms under the MinGW directory:
Refer to the Qt Plugins documentation for more details.