Get Involved/development/IDE configuration/Qt Creator: Difference between revisions

From KDE Community Wiki
(Add entire chapter)
m (Format code)
Line 7: Line 7:
Edit ~/.config/kdesrc-buildrc . It should look like:
Edit ~/.config/kdesrc-buildrc . It should look like:


{{Input|1=<nowiki>
global
global
...                                                                                                     
...                                                                                                     
Line 18: Line 19:
...                                                                                 
...                                                                                 
     cmake-options -DCMAKE_BUILD_TYPE=Debug
     cmake-options -DCMAKE_BUILD_TYPE=Debug
</nowiki>}}


The line above is important in order to use the debugger from Qt Creator.
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 ".
Make sure you have the correct number on the line <code>num-cores </code>.


Build kcalc, make sure there are no errors:
Build kcalc, make sure there are no errors:
{{Input|1=<nowiki>
kdesrc-build --include-dependencies kcalc
kdesrc-build --include-dependencies kcalc
</nowiki>}}


E.g. install Qt Creator from your current Linux distro's packages. E.g.
E.g. install Qt Creator from your current Linux distro's packages. E.g.
{{Input|1=<nowiki>
apt install qtcreator.
apt install qtcreator.
</nowiki>}}


Start Qt Creator. E.g. from a terminal
Start Qt Creator. E.g. from a terminal
{{Input|1=<nowiki>
qtcreator &
qtcreator &
</nowiki>}}


From the qtcreator main menu
From the qtcreator main menu
> File > Close all projects and editors
> File > Close all projects and editors
> File > Open file or project
> File > Open file or project
~/kde/src/kcalc/CMakeLists.txt
<code>~/kde/src/kcalc/CMakeLists.txt</code>
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.
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 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: <code>main(int, char***) -> int</code>.
In the left bottom side of qtcreator you can see the "Project Deploy Kit Build Run" selector. It says "kcalc (Desktop kit icon) Debug".
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/).
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 <code>~/kde/build/kcalc/bin/kcalc</code>. 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'.
What I cannot do is, I cannot navigate to files from ~/kde/src/. E.g. If in kcalc.cpp, after <code>int main(int argc, char *argv[])</code>, 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/.
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/.
Line 54: Line 62:
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".
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.
Now, I open the file "kcalc.cpp", navigate to <code>int main(int argc, char *argv[])</code> 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
If I edit the source code of
"int main(int argc, char *argv[])
{{Input|1=<nowiki>
int main(int argc, char *argv[])
{
{
     int a = argc + 1;"
     int a = argc + 1;
</nowiki>}}


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
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;"
<code>int a = argc + 1;</code>
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.
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.
{{Input|1=<nowiki>
ps aux | grep kcalc
ps aux | grep kcalc
usern  187843  0.8  0.3 2162696 105592 pts/4  Sl  20:26  0:00 ~/kde/build/kcalc/bin/kcalc
usern  187843  0.8  0.3 2162696 105592 pts/4  Sl  20:26  0:00 ~/kde/build/kcalc/bin/kcalc
</nowiki>}}

Revision as of 02:59, 1 May 2022

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