Get Involved/development/IDE configuration/Qt Creator

From KDE Community Wiki
Revision as of 02:53, 1 May 2022 by Nmariusp (talk | contribs) (Add entire chapter)

Qt Creator is an IDE from Qt.

Qt Creator and kdesrc-build

After you configure kdesrc-build and you can correctly build a KDE projects such as kcalc.

Edit ~/.config/kdesrc-buildrc . It should look like:

global ...

   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 --include-dependencies kcalc

E.g. install Qt Creator from your current Linux distro's packages. E.g. apt install qtcreator.

Start Qt Creator. E.g. from a terminal qtcreator &

From the qtcreator main menu > File > Close all projects and editors > File > Open file or project ~/kde/src/kcalc/CMakeLists.txt Left Sidebar > Edit sidebar > Select "File System" from the combobox. In the "File System" left hand treeview > double click on the file kcalc.cpp. Click inside the source code in text editor. In the text editor's top bar the text in the combobox changes from "<No Symbols>" to "<Select Symbol>". From this combobox (i.e. the Symbols combobox), select the last item: "main(int, char***) -> int". In the left bottom side of qtcreator you can see the "Project Deploy Kit Build Run" selector. It says "kcalc (Desktop kit icon) Debug".

At this moment the following work correctly: I can edit the source code correctly. I can run the executable that I want via qtcreator main menu > Debug > Start debugging > Start and debug external application "~/kde/build/kcalc/bin/kcalc". I.e. I can program inside the debugger while debugging. I can navigate the source code, i.e. go to *.h/*.cpp/Ctrl + click on symbol/right click on symbol > Follow symbol under cursor/F2. I can only navigate towards the *.h files that exist in /usr and to the source code in the project kcalc (i.e. the source code in ~/kde/src/kcalc/).

What I cannot do is, I cannot navigate to files from ~/kde/src/. E.g. If in kcalc.cpp, after "int main(int argc, char *argv[])", I want to navigate the symbol "KLocalizedString" it refuses to navigate and says "use of undeclared identifier 'KLocalizedString'.

When I navigate the symbol "KCrash", it navigates to the file "/usr/include/KF5/KCrash/kcrash.h:35". Which is wrong. As I use all non KDE libraries from Kubuntu 22.04, I use qt from Kubuntu 22.04. But I use all of the KDE source code from kdesrc-build, i.e. from ~/kde/src/.

I click on the left button "Projects". The GUI editor for CMake is shown. In Desktop > Build > "Key Value" list view I can see "KF5Auth_DIR /usr/lib/x86_64-linux-gnu/cmake/KF5Auth". That means that qtcreator thinks that I use /usr for KDE source code and includes. I use ~/kde/src/.

Tools > Options > Kits > remove kit "Imported Kit".

I click on the left button "Projects". The GUI editor for CMake is shown. I select "Imported Kit" > Build. Delete the two build configurations "Debug" and "Debug2". I press the button "Import Existing Build..." > "~/kde/build/kcalc". In Imported Kit > Build it creates a build configuration named "Debug". In Desktop > Build > "Key Value" list view I can see "KF5Auth_DIR /home/nmariusp/kde/usr/lib/x86_64-linux-gnu/cmake/KF5Auth". That means that qtcreator uses ~/kde/src/ for KDE source code and includes. In the left bottom side of qtcreator is the "Project Deploy Kit Build Run" selector. Click on it. It says "kcalc + Deploy configuration + Kit = Imported Kit + Build = Debug + Run = kcalc".

Now, I open the file "kcalc.cpp", navigate to "int main(int argc, char *argv[])" and I can see that qtcreator recognizes the symbols "QApplication (/usr/include/x86_64-linux-gnu/qt5/QtWidgets/qapplication.h:72)", "KLocalizedString (~/kde/usr/include/KF5/KI18n/klocalizedstring.h:98)", "KCrash (~/kde/usr/include/KF5/KCrash/kcrash.h:35)", "KNumber (~/kde/src/kcalc/knumber/knumber.h:17)". In order to copy file path and line number, right click on the tab (i.e. document combobox) > Copy path and line number. Now I can correctly navigate to all symbols.

If I edit the source code of "int main(int argc, char *argv[]) {

   int a = argc + 1;"

and place a breakpoint on this new line. I click on the left bottom button "Start debugging of startup project" (the green triangle + ladybug icon). It builds. And starts the correct executable in the debugger and breaks on line "int a = argc + 1;" And I can step in the debugger. And I can see how the value of the local variable a changes from 0 to 2. Now I can Build project kcalc (Ctrl+B). The button "Run Ctrl+R" also works correctly. ps aux | grep kcalc usern 187843 0.8 0.3 2162696 105592 pts/4 Sl 20:26 0:00 ~/kde/build/kcalc/bin/kcalc