Get Involved/development/IDE configuration/Qt Creator: Difference between revisions
→Load a KDE git repository in Qt Creator: The "Batch Edit" step is mandatory |
|||
Line 99: | Line 99: | ||
You can build by pressing the hammer icon on the lower left with tooltip "Build Project Ctrl+B". Or from the Qt Creator main menu > Build > "Build Project Ctrl+B". | You can build by pressing the hammer icon on the lower left with tooltip "Build Project Ctrl+B". Or from the Qt Creator main menu > Build > "Build Project Ctrl+B". | ||
Left Sidebar > Switch to Edit mode (Ctrl+2) > Select "Projects" from the combobox. In the "Projects" left hand treeview > kcalc > kcalc > Source Files > double click on the file kcalc.cpp. The file kcalc.cpp will be shown in the editor view. Click inside the source code in text editor. | Left Sidebar > Switch to Edit mode (Ctrl+2) > Select "Projects" from the combobox (the other interesting combobox item is "File System"). In the "Projects" left hand treeview > kcalc > kcalc > Source Files > double click on the file kcalc.cpp. The file kcalc.cpp will be shown in the editor view. Click inside the source code in text editor. | ||
In the text editor's top bar > function/identifier/method/type/symbols combobox, select the last item: <code>main(int, char | In the text editor's top bar > function/identifier/method/type/symbols combobox, select the last item: <code>main(int, char**) -> int</code>. Click on the line with the opening curly bracket of the function main. From the main menu > Debug > Set or Remove Breakpoint (F9). | ||
Left Sidebar > Start debugging of startup project. The debugger will start correctly and break on the source code line with the curly bracket. | Left Sidebar > Start debugging of startup project. The debugger will start correctly and break on the source code line with the curly bracket. | ||
From the main menu Debug > Step Over (F10)/Step Into(F11)/Step Out (Shift+F11). | From the main menu Debug > Step Over (F10)/Step Into(F11)/Step Out (Shift+F11). |
Revision as of 17:32, 10 March 2023
Qt Creator is an IDE from Qt.
A screen recording version is available https://www.youtube.com/watch?v=ASnDeEaXnbI
Features
Qt Creator is a good choice when starting to contribute to KDE.
Qt Creator has: support for kdesrc-build, a good debugger, source code navigation, Qt widgets UI designer, basic QML editor, QML debugger, Qt resources editor, Qt project templates, good CMake support, C++ static analyzers.
Additional features:
- Source code navigation: switch header/source, follow symbol, switch between function declaration/definition, find references, open type hierarchy, open include hierarchy.
- Refactor rename symbol.
- Views: class view, tests view, document outline view and document outline combo box, CMake structure view, file system view.
For best results, download Qt Creator from the Qt website. https://www.youtube.com/watch?v=QVgInye6HDA
kdesrc-build
After you configure kdesrc-build and you can correctly build a KDE project such as kcalc.
Edit ~/.config/kdesrc-buildrc . It should look like:
... include-dependencies true ... kdedir ~/kde/usr ... source-dir ~/kde/src ... build-dir ~/kde/build ... cmake-options -DCMAKE_BUILD_TYPE=Debug ...
The line above is important in order to use the debugger from Qt Creator.
Make sure you have the correct number on the line num-cores
.
Build kcalc, make sure there are no errors:
kdesrc-build kcalc
Install Qt Creator
Install Qt Creator. E.g. download from the Qt website https://www.qt.io/ the latest version. Video version https://www.youtube.com/watch?v=QVgInye6HDA
The newest version of Qt Creator installed from the Qt website will have the latest features and the latest bug fixes.
Or e.g. from your current Linux distribution's packages. E.g.
apt install qtcreator
Load a KDE git repository in Qt Creator
We use kcalc as the example KDE git repository. Make sure it was built correctly using kdesrc-build.
kdesrc-build kcalc
Start Qt Creator. E.g. from the KDE Application Launcher (or from KRunner Alt+F2).
From the qtcreator main menu
> File > Close All Projects and Editors
> File > Open File or Project ~/kde/src/kcalc/CMakeLists.txt
Left Sidebar > Switch to Projects mode Ctrl+5 > Manage Kits... Under "Kits > Manual", remove all kits except "Desktop (default)". E.g. select Manual > "Imported Kit" > press the "Remove" button > press the "Apply" button.
Button "Import Existing Build..." > Directory: ~/kde/build/kcalc > Choose.
CMake should be configured correctly. CMake is run automatically, see "General Messages Alt+6".
Left Sidebar > Switch to Projects mode Ctrl+5 > Active project: kcalc. Build & Run: not the Desktop kit (e.g. "Imported Kit") > Build. Build Settings > Edit build configuration: "Debug2".
Left Sidebar > Switch to Projects mode Ctrl+5 > Build & Run: not the Desktop kit (e.g. "Imported Kit") > Run. Run Settings > Run > Run configuration: select "kcalc". This is the CMake executable target for the GUI application kcalc. The other items in the combobox e.g. "knumbertest" are binary executable (CTest type) tests. Environment > Use Build Environment > press the Details button > press the "Reset" button if possible > press the "Batch Edit..." button. Paste in there, the text below, then press the OK button.
PATH=+/home/username/kde/usr/bin XDG_DATA_DIRS=+/home/username/kde/usr/share XDG_CONFIG_DIRS=+/home/username/kde/usr/etc/xdg QT_PLUGIN_PATH=+/home/username/kde/usr/lib/x86_64-linux-gnu/plugins QML2_IMPORT_PATH=+/home/username/kde/usr/lib/x86_64-linux-gnu/qml QT_QUICK_CONTROLS_STYLE_PATH=+/home/username/kde/usr/lib/x86_64-linux-gnu/qml/QtQuick/Controls.2/
The block above is the file ~/kde/build/prefix.sh
translated to the syntax of Qt Creator "Batch Edit".
Click on the left sidebar, the button above "Run Ctrl+R". It should show: Project: kcalc. Kit: not the Desktop kit (e.g. "imported Kit"). Deploy: Deploy Configuration. Build: Debug2. Run: kcalc.
CMake configure was run automatically. You can run it again from the Qt Creator main menu > Build > Run CMake.
You can build by pressing the hammer icon on the lower left with tooltip "Build Project Ctrl+B". Or from the Qt Creator main menu > Build > "Build Project Ctrl+B".
Left Sidebar > Switch to Edit mode (Ctrl+2) > Select "Projects" from the combobox (the other interesting combobox item is "File System"). In the "Projects" left hand treeview > kcalc > kcalc > Source Files > double click on the file kcalc.cpp. The file kcalc.cpp will be shown in the editor view. Click inside the source code in text editor.
In the text editor's top bar > function/identifier/method/type/symbols combobox, select the last item: main(int, char**) -> int
. Click on the line with the opening curly bracket of the function main. From the main menu > Debug > Set or Remove Breakpoint (F9).
Left Sidebar > Start debugging of startup project. The debugger will start correctly and break on the source code line with the curly bracket.
From the main menu Debug > Step Over (F10)/Step Into(F11)/Step Out (Shift+F11).