Jump to content

User:Nmariusp/Qt Creator: Difference between revisions

From KDE Community Wiki
Nmariusp (talk | contribs)
Nmariusp (talk | contribs)
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
Qt Creator is an IDE from Qt.
Qt Creator is an IDE from Qt.


A screen recording version is available https://www.youtube.com/watch?v=ASnDeEaXnbI https://www.youtube.com/watch?v=QVgInye6HDA
A screen recording version is available https://www.youtube.com/watch?v=hNk_wjw1sZE https://www.youtube.com/watch?v=1mt3X6JgcOA
 
See also https://community.kde.org/Get_Involved/development/IDE_configuration/Qt_Creator


== Features ==
== Features ==
Line 7: Line 9:
Qt Creator is a good choice when starting to contribute to KDE.  
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.
Qt Creator has: support for kdesrc-build, kde-builder, 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:
Additional features:
Line 14: Line 16:
* Views: class view, tests view, document outline view and document outline combo box, CMake structure view, file system view.
* 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
For best results, download Qt Creator from the Qt website.


==Install Qt Creator==
==Install Qt Creator==
Line 53: Line 55:
Please make sure that you use Qt Creator version 15 or newer.
Please make sure that you use Qt Creator version 15 or newer.


We'll use kcalc as an example KDE Git repository. First, make sure it was built correctly using <code>kdesrc-build</code>.
I configure kde-builder to use the CMake build configuration "Debug" in order to be able to use the debugger in the IDE.
 
<pre>
  cmake-options: >
    -DCMAKE_BUILD_TYPE=Debug
</pre>
 
We'll use kcalc as an example KDE module and git repository. First, make sure it was built correctly using <code>kde-builder</code>.


<pre>
<pre>
kdesrc-build kcalc
kde-builder kcalc
</pre>
</pre>


Line 105: Line 114:
</pre>
</pre>


Save the text block above to file <code>~/kde/expanded-prefix-sh.txt</code>. The same text block will be needed when opening in the IDE Qt Creator other KDE project. The content of this file is also needed when running or debugging a KDE project in other IDEs e.g. JetBrains CLion.
Save the text block above to file <code>~/kde/expanded-prefix-sh.txt</code>. The same text block will be needed when opening in the IDE Qt Creator other KDE projects. The content of this file is also needed when running or debugging a KDE project in other IDEs e.g. JetBrains CLion.


Copy to clipboard the content of the file <code>~/kde/expanded-prefix-sh.txt</code>. From the Qt Creator left sidebar > Projects with tooltip "Switch to Projects mode Ctrl+5" > under the bold text "Build & Run" > Run. The "Run Settings" page is shown. In the combobox "Run configuration:" select "kcalc", in the "Environment" group box > expand "Details", to the right of the button "Append Path..." is an empty multi line edit box, paste inside this edit box. As a safety measure you can check the checkbox "Show in Application Output when running". When Qt Creator runs or debugs the kcalc process, the values of the environment values of the process kcalc are shown in the tool window "Application Output Alt+3". Make sure that the value of the environment variables is correct.
Copy to clipboard the content of the file <code>~/kde/expanded-prefix-sh.txt</code>. From the Qt Creator left sidebar > Projects with tooltip "Switch to Projects mode Ctrl+5" > under the bold text "Build & Run" > Run. The "Run Settings" page is shown. In the combobox "Run configuration:" select "kcalc", in the "Environment" group box > expand "Details", to the right of the button "Append Path..." is an empty multi line edit box, paste inside this edit box. As a safety measure you can check the checkbox "Show in Application Output when running". When Qt Creator runs or debugs the kcalc process, the values of the environment values of the process kcalc are shown in the tool window "Application Output Alt+3". Make sure that the value of the environment variables is correct.
Line 121: Line 130:


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 context menu actions. You can make your run configuration to launch custom binary - dolphin. See [https://doc.qt.io/qtcreator/creator-run-settings.html#specifying-a-custom-executable-to-run documentation] on how to configure that.
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 context menu actions. You can make your run configuration to launch custom binary - dolphin. See [https://doc.qt.io/qtcreator/creator-run-settings.html#specifying-a-custom-executable-to-run documentation] on how to configure that.
==See also==
https://community.kde.org/User:Nmariusp/Clion

Latest revision as of 23:39, 22 December 2024

Qt Creator is an IDE from Qt.

A screen recording version is available https://www.youtube.com/watch?v=hNk_wjw1sZE https://www.youtube.com/watch?v=1mt3X6JgcOA

See also https://community.kde.org/Get_Involved/development/IDE_configuration/Qt_Creator

Features

Qt Creator is a good choice when starting to contribute to KDE.

Qt Creator has: support for kdesrc-build, kde-builder, 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.

Install Qt Creator

Using the Qt online installer - recommended

The newest version of Qt Creator installed from the Qt website will have the latest features and the latest bug fixes.

Video version https://www.youtube.com/watch?v=QVgInye6HDA

Go to https://www.qt.io/ on the top right click on the button "Download. Try.". The web browser navigates to "https://www.qt.io/download", in the top right quarter of the page it says "Open source user? Find out how you can use Qt under the (L)GPL and contribute to the Qt project. Download open source". Click on the button "Download open source". The web browser navigates to https://www.qt.io/download-open-source. In the bottom middle of the page it says "Looking for Qt binaries? Find them in the Qt Online Installer. It will steer you to the right download version and help you install tools and add-on components that are available for your open source license. Download the Qt Online Installer". Click on the button "Download the Qt Online Installer" > Linux > "Qt Online Installer for Linux (64-bit)". A file named e.g. qt-unified-linux-x64-4.6.1-online.run is downloaded.

chmod +x qt-unified-linux-x64-4.6.1-online.run
./qt-unified-linux-x64-4.6.1-online.run

The Qt online installer will start. The Qt online installer requires that you create an online user account for https://www.qt.io .

From Linux OS binary packages

E.g.

apt install qtcreator

QML Designer

Qt Creator has a "forms editor" for QML. You can enable it from the Qt Creator main menu > Help > About Plugins... > Qt Quick > enable "QmlDesigner". If it asks you to restart Qt Creator, do it.

Test it. From Qt Designer main menu > File > Close all Files and Editors. File > New Project... > Application (Qt) > Qt Quick Application, finish the wizard correctly. Open the file "Main.qml" in "Switch to Edit mode Ctrl+2". In the left hand side, choose "Switch to Design mode Ctrl+3".

From the Qt Creator main menu > View > Workspaces > Views-All. Close all of the tool windows (views) that you do not need, e.g. "3D", "States", "Timeline", "Curves", "Transitions".

Open a KDE project in Qt Creator >= 15

Please make sure that you use Qt Creator version 15 or newer.

I configure kde-builder to use the CMake build configuration "Debug" in order to be able to use the debugger in the IDE.

  cmake-options: >
    -DCMAKE_BUILD_TYPE=Debug

We'll use kcalc as an example KDE module and git repository. First, make sure it was built correctly using kde-builder.

kde-builder kcalc

Start Qt Creator (for example, from the KDE Application Launcher).

From the Qt Creator main menu, select File > "Open File or Project" > ~/kde/build/kcalc/CMakeCache.txt. Click on the button "Configure Project".

Run

cat ~/kde/build/kcalc/prefix.sh

says:

export PATH=/home/username/kde/usr/bin:$PATH
export XDG_DATA_DIRS=/home/username/kde/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
export XDG_CONFIG_DIRS=/home/username/kde/usr/etc/xdg:${XDG_CONFIG_DIRS:-/etc/xdg}
export QT_PLUGIN_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/plugins:$QT_PLUGIN_PATH
export QML2_IMPORT_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/qml:$QML2_IMPORT_PATH
export QT_QUICK_CONTROLS_STYLE_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/qml/QtQuick/Controls.2/:$QT_QUICK_CONTROLS_STYLE_PATH
export MANPATH=/home/username/kde/usr/share/man:${MANPATH:-/usr/local/share/man:/usr/share/man}
export SASL_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/sasl2:${SASL_PATH:-/usr/lib/x86_64-linux-gnu/sasl2}

Run:

source ~/kde/build/kcalc/prefix.sh

echo PATH=$PATH
echo XDG_DATA_DIRS=$XDG_DATA_DIRS
echo XDG_CONFIG_DIRS=$XDG_CONFIG_DIRS
echo QT_PLUGIN_PATH=$QT_PLUGIN_PATH
echo QML2_IMPORT_PATH=$QML2_IMPORT_PATH
echo QT_QUICK_CONTROLS_STYLE_PATH=$QT_QUICK_CONTROLS_STYLE_PATH
echo MANPATH=$MANPATH
echo SASL_PATH=$SASL_PATH

says:

PATH=/home/username/kde/usr/bin:/home/username/.local/bin:/home/username/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts
XDG_DATA_DIRS=/home/username/kde/usr/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop
XDG_CONFIG_DIRS=/home/username/kde/usr/etc/xdg:/home/username/.config/kdedefaults:/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/:
MANPATH=/home/username/kde/usr/share/man:/usr/local/share/man:/usr/share/man
SASL_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/sasl2:/usr/lib/x86_64-linux-gnu/sasl2

Save the text block above to file ~/kde/expanded-prefix-sh.txt. The same text block will be needed when opening in the IDE Qt Creator other KDE projects. The content of this file is also needed when running or debugging a KDE project in other IDEs e.g. JetBrains CLion.

Copy to clipboard the content of the file ~/kde/expanded-prefix-sh.txt. From the Qt Creator left sidebar > Projects with tooltip "Switch to Projects mode Ctrl+5" > under the bold text "Build & Run" > Run. The "Run Settings" page is shown. In the combobox "Run configuration:" select "kcalc", in the "Environment" group box > expand "Details", to the right of the button "Append Path..." is an empty multi line edit box, paste inside this edit box. As a safety measure you can check the checkbox "Show in Application Output when running". When Qt Creator runs or debugs the kcalc process, the values of the environment values of the process kcalc are shown in the tool window "Application Output Alt+3". Make sure that the value of the environment variables is correct.

Now you can run kcalc correctly, from the Qt Creator main menu > Build > Run Ctrl+R.

Now you can debug kcalc correctly, from the Qt Creator main menu > Debug > Start Debugging > Start Debugging of Startup Project F5. The debugger can stop on the first line of the C++ process entry point function "main()", from the Qt Creator main menu > Debug > "Start and Break on Main F10".

Build the project

You can build by pressing the hammer icon on the lower left with tooltip "Build Project "kcalc" Ctrl+B", or from the Qt Creator main menu > Build > "Build Project "kcalc" Ctrl+B".

Tips and Tricks

Custom executable to run

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 context menu actions. You can make your run configuration to launch custom binary - dolphin. See documentation on how to configure that.

See also

https://community.kde.org/User:Nmariusp/Clion