4. Pregătirea lucrului cu QtCreator și QGIS
QtCreator is an IDE from the makers of the Qt library. With QtCreator you can build any C++ project, but it’s really optimised for people working on Qt based applications (including mobile apps).
Qt Creator is available on all major platforms and can be downloaded from https://www.qt.io/download (Go the open source route). The installation procedure depends on your platform.
If you are running a Unix-like platform, you can use the command line, eg on Debian:
sudo apt install qtcreator qtcreator-doc
After installing you should find it in your menu.
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 installation.
On our system we have checked out the code into
$HOME/dev/cpp/QGIS and the
rest of the article is written assuming that. You should update these paths as
appropriate for your local system.
After launching QtCreator do
Apoi, selectați în dialogul care se va deschide, următorul fișier:
QtCreator will parse the project and you will be prompted for a build location and options in the Configure Project dialog.
Since we want QGIS to have debugging capabilities we will only enable the debug entry and fill it with our build location:
Fill the path with the build directory. For our purpose, we create a specific build dir for QtCreator:
It’s probably a good idea to create separate build directories for different branches if you can afford the disk space.
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.
We want to tweak a few things before we start to build.
Click on the Projects icon on the left of the QtCreator window.
Select the Build settings tab (normally active by default).
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 for 3D rendering
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:
Press the Custom Process Stepmenu and select
Fill the new form as follows:
-j4to use 4 cores (setting depends on your device)
Also, if you want to reduce your build times, you can do it with
make with similar build options. You’d need to set it as
the CMake generator:
Select the Desktop (default) kit entry, displaying its properties
Press Change… next to CMake generator
You are now ready to build. Press the 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 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.
CMAKE_INSTALL_PREFIXto somewhere you have write access to (we use
$HOME/apps). This would avoid overwriting an existing QGIS installs (by your package manager for example).
Press Apply Configuration Changes to update the settings
Press the button
When the build is complete, you’ll find the
qgisexecutable in the
Acum puteți rula și depana QGIS. Pentru a seta un punct de pauză, pur și simplu deschideți un fișier sursăm apoi faceți clic în coloana din stânga.
Now launch QGIS under the debugger by clicking the Start Debugging in the bottom left of the window.