Important

La traduction est le fruit d’un effort communautaire auquel vous pouvez prendre part. Cette page est actuellement traduite à 53.85%.

4. Découvrir et aller plus loin avec QtCreator et QGIS

QtCreator est un environnement de développement conçu par les créateurs de la bibliothèque Qt. Avec QtCreator, vous pouvez construire n’importe quel projet C++, mais il est vraiment optimisé pour les personnes travaillant sur des applications basées sur Qt (y compris les applications mobiles).

4.1. Installation de QtCreator

Qt Creator est disponible sur toutes les principaux systèmes d’exploitation et peut être téléchargé à partir de https://www.qt.io/download (Go open source). La procédure d’installation dépend de votre plate-forme.

Si vous utilisez un système d’exploitation de type Unix, vous pouvez utiliser la ligne de commande, par exemple sur Debian :

sudo apt install qtcreator qtcreator-doc

Après l’installation, vous devriez le trouver dans votre menu.

4.2. Paramétrer votre projet

We assume you have already got a local QGIS clone containing the source code, and have installed all needed build dependencies etc. There are detailed instructions for git access and dependency requirements.

Sur notre système, nous avons extrait le code dans HOME/dev/cpp/QGIS et le reste de l’article est rédigé en supposant cela. Vous devriez mettre à jour ces chemins en fonction de votre système local.

Après avoir lancé QtCreator, faites Fichier ► Ouvrir Fichier ou Projet.

Utilisez ensuite la boîte de dialogue de sélection de fichier pour naviguer et ouvrir ce fichier:

$HOME/dev/cpp/QGIS/CMakeLists.txt
../../_images/selectCMakeLists.png

QtCreator va analyser le projet et vous serez invité à choisir un emplacement de compilation et des options dans la boîte de dialogue Configure Project.

Puisque nous voulons que QGIS ait des capacités de débogage, nous n’allons rendre active que l’option pour déboguer et la remplir avec notre emplacement de compilation :

  1. Cocher checkbox Select all kits permettant l’entrée Desktop

  2. Décochez tout sauf le sous-item checkbox Débogage

  3. Fill the path with the build directory. For our purpose, we create a specific build dir for QtCreator:

    $HOME/dev/cpp/QGIS/build-master-qtcreator
    

    It’s probably a good idea to create separate build directories for different branches if you can afford the disk space.

    ../../_images/configureProject.png

That’s the basics of it. Press the Configure Project button and QtCreator will start scanning the source tree for autocompletion support and do some other housekeeping stuff in the background.

../../_images/configurationDone.png

We want to tweak a few things before we start to build.

4.3. Paramétrez votre environnement de compilation

Click on the Projects icon on the left of the QtCreator window.

../../_images/leftPanel.png

Sélectionnez l’onglet de paramétrage Build (normalement actif par défaut)

../../_images/buildSettings.png

The dialog shows the Debug build configuration and allows you to edit settings under the CMake section. While the default configuration should be enough for a first pass, depending on your needs, you may want to enable more features such as:

  • WITH_3D = ON pour le rendu 3D

  • WITH_CUSTOM_WIDGETS = ON to add QGIS custom widgets for interface design

Press Apply Configuration Changes.

By default, Qt Creator uses all the CPU cores available to speed the build with maximum parallelization. To avoid that your computer freezes, you should specify a smaller number of cores. Under the Build Steps section:

  1. Press the Add build step ► menu and select Custom Process Step

  2. Remplissez le nouveau formulaire comme ci-après :

    • Commande: make

    • Arguments: -j4 to use 4 cores (setting depends on your device)

    • Dossier de travail: %{buildDir}

../../_images/customProcess.png

Note

Also, if you want to reduce your build times, you can do it with ninja, an alternative to make with similar build options. You’d need to set it as the CMake generator:

  1. Open Tools ► Options ► Build & Run ► Kits

  2. Select the Desktop (default) kit entry, displaying its properties

  3. Press Change… next to CMake generator

You are now ready to build. Press the build Build button at the left bottom of the dialog (or Ctrl+B) to launch the project build! Qt Creator will begin compiling and this may take some time the first time, depending on your device.

At the end of the compilation, you can run QGIS by pressing the runInstall Run button.

The compilation of QGIS also generates binaries in the build directory. Hence you can execute QGIS from the command line using:

cd $HOME/dev/cpp/QGIS/build-master-qtcreator
./output/bin/qgis

Sometimes you may want to install QGIS as an executable, outside the build directory.

  1. Set the CMAKE_INSTALL_PREFIX to somewhere you have write access to (we use $HOME/apps). This would avoid overwriting an existing QGIS installs (by your package manager for example).

    ../../_images/customInstallPrefix.png
  2. Press Apply Configuration Changes to update the settings

  3. Appuyez sur le bouton build

  4. When the build is complete, you’ll find the qgis executable in the $HOME/apps/bin folder.

4.4. Exécution et déboguage

Maintenant, vous êtes prêts à lancer et à déboguer QGIS. Pour insérer un point d’arrêt, ouvrez simplement un fichier source et cliquez dans la colonne de gauche.

../../_images/breakPoint.jpeg

Now launch QGIS under the debugger by clicking the runDebug Start Debugging in the bottom left of the window.