Qt Creator
Supports many KDE project technologies including Qt, QML, C++, and CMake.
Last updated
Supports many KDE project technologies including Qt, QML, C++, and CMake.
Last updated
Qt Creator is a cross-platform C++, JavaScript, Python and QML IDE.
This article will show you how to configure and develop KDE projects in Qt Creator. We will use KCalc as an example project.
Note
This article assumes you use KDE Builder. The older tool kdesrc-build does not support Qt Creator configuration generation.
To allow kde-builder to generate Qt Creator project files, add the following to your ~/.config/kdesrc-buildrc
:
Instead of enabling the generate-qtcreator-project-config
option globally, you may choose to enable it only for a single project:
Ensure you have successfully built kcalc following the kde-builder instructions.
In case you enabled generate-qtcreator-project-config
after you have built kcalc previously, or do not want to edit your config, you can generate CLion configs by running:
Unfortunately, Qt Creator has limited abilities for generating project configuration externally (for more info, see kde-builder developer documentation). So the configuration is made half manually and half automatically.
See official documentation: Configuring Projects.
From the Qt Creator main menu, select File | Open File or Project or press Ctrl + Shift + O and select the ~/kde/src/kcalc/CMakeLists.txt
file.
Note
In case you want to start configuration from scratch, just delete the generated CMakeLists.txt.user
file and reopen a project.
See the official documentation: Open projects.
If you are opening the project for the first time, the "Configure Project" view will be opened.
{{< figure width="80%" src="configure_project_view.png)
Press the "Select all kits" checkbox several times to deselect every kit. Then create "KDE Builder kit" (if not done yet), and select it.
Temporary kits
If the project has a CMakePresets.json
in its root directory (KCalc does), you will see many temporary kits created for the project. You do not need them, and need to deselect all of them.
For your convenience, you can remove all temporary kits from the project, so they are not shown in the available kits in the Project mode. You can do this in "Manage Kits". In case you want them in the future, you could do Build | Reload CMake Presets.
{{< figure width="60%" src="remove_temporary_kits.png)
Alternatively, you can keep temporary kits there, but deactivate them for the project. If you accidentally clicked on an unwanted kit in "Build & Run", it got activated. To disable it again, click on its name with right mouse button, and select "Disable Kit for all projects".
{{< figure width="300px" src="disabling_activated_kit.png)
Creating the KDE Builder kit
The very first time you want to use kde-builder with Qt Creator, you will need to create a kit named "KDE Builder kit".
Tip
This kit is a global IDE setting, so you will only need to do it once.
In the left sidebar, switch to "Projects" mode (Ctrl+5), then click "Manage Kits...".
{{< figure width="300px" src="manage_kits_button.png)
Press the "Add" button, and fill in the fields as follows:
Open the "Projects" mode (Ctrl + 5), go to "Build & Run", "KDE Builder kit", then click "Build".
The "Build Settings" view will open.
Add new build configuration
Under the "Edit build configuration", press the "Add" button to add a new build configuration, select any type, for example, "Debug", and give it a name, for example, "KDE Builder build configuration".
CMake section
Under the "Build directory" field, enter the build directory of the module, in our example it will be ~/kde/build/kcalc
.
Under "Build type", write the build type that was configured in kde-builder. This should be a valid value.
In the "Initial Configuration" tab, press "Batch Edit", then paste the text from the generated file located at ~/kde/src/kcalc/.qtcreator/cmake_Initial_Configuration.txt
.
Under "Use Build Environment", press "Details" to expand this setting. Under "Base environment for the CMake configure step", select "Build Environment".
Build Steps section
In the "CMake arguments" field, enter the "-j" and a value of your num-cores option, for example, "-j 10".
Under targets, ensure you selected "all".
Build Environment section
Copy the text from the generated file located at ~/kde/src/kcalc/.qtcreator/cmake_Configure_and_Build_Environment.txt
and paste to the text field in this section.
Open the "Projects" mode (Ctrl + 5), go to "Build & Run", "KDE Builder kit", then click "Run".
Deployment section
Under "Deploy configuration", press "Add Deploy Step" and select "CMake install".
For convenience, you can rename the configuration as "KDE Builder Deploy configuration"
Run section
In the "Run configuration" field, press Add button, and select "Custom Executable".
Rename the configuration for your convenience, for example as "KDE Builder Run configuration".
In the "Executable" field, specify the path to the installed project binary. In our example, it is ~/kde/usr/bin/kcalc
.
Environment section
Click "Details" to expand this setting.
In the "Base environment for this run configuration" select "System Environment".
Copy the text from the generated file located at ~/kde/src/kcalc/.qtcreator/Run_Environment.txt
and paste it into the text field in this section.
Note: if you want to see debugging messages, you can add corresponding variables here. See Using error messages for more information.
In the left bottom corner, in the configuration selector, ensure the correct configuration is selected (i.e. for the "kcalc" project, the Build, Deploy and Run configurations applied are those that we configured).
You are now ready to start developing.
Switch to "Edit" mode (Ctrl + 2). Open the kcalc.cpp
, and make a breakpoint. For example, let's do it in main()
. In the text editor's top bar, open the "Select Symbol" drop-down menu, scroll to the bottom of the options, and select the last item in it: main(int, char**) -> int
. Click on the line with the opening curly bracket of the function main()
.
Now when you click the Debug button (that has a green play icon with a bug in its corner), all the preparation steps will be done automatically (CMake configure, build, deploy and run).
The debugger will stop at the breakpoint, and you can inspect variables, step into functions, etc.
When developing a library, it may be convenient to launch some application that uses it, from the current project. For example, you work with Ark's libraries used in Dolphin's context menu actions. You can make your run configuration to launch the custom binary dolphin
. See Qt Creator settings: Specifying a custom executable to run to configure that.