Iniciando y ejecutando con QtCreator y QGIS

QtCreator is a newish 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(4) based applications (including mobile apps). Everything I describe below assumes you are running Ubuntu 11.04 “Natty”.

Instalando QtCreator

Esta parte es fácil:

sudo apt-get install qtcreator qtcreator-doc

Después de instalar lo debería encontrar en su menú gnome

Configurando su proyecto

I’m assuming 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 my system I 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.

Cuando inicie QtCreator haga:

Archivo -> Abrir Archivo o Proyecto

Luego use la selección de archivo resultante para navegar a y abrir este archivo:

$HOME/dev/cpp/QGIS/CMakeLists.txt
../../../../_images/image01.jpeg

Next you will be prompted for a build location. I create a specific build dir for QtCreator to work in under:

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

Probablemente es una buena idea crear directorios separados de construcción para diferentes ramas si se lo permite su espacio de disco.

../../../../_images/image02.jpeg

Next you will be asked if you have any CMake build options to pass to CMake. We will tell CMake that we want a debug build by adding this option:

-DCMAKE_BUILD_TYPE=Debug
../../../../_images/image03.jpeg

That’s the basics of it. When you complete the Wizard, 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 though.

Configurando su ambiente de armado

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

../../../../_images/image04.jpeg

Seleccione la pestaña de configuración de construcción (por defecto está normalmente activa).

../../../../_images/image05.jpeg

We now want to add a custom process step. Why? Because QGIS can currently only run from an install directory, not its build directory, so we need to ensure that it is installed whenever we build it. Under “Build Steps”, click on the “Add BuildStep” combo button and choose “Custom Process Step”.

../../../../_images/image06.jpeg

Ahora definimos los siguientes detalles:

Habilitar paso en proceso personalizado: [yes]

Comando: hacer

Directorio de trabajo: $HOME/dev/cpp/QGIS/build-master-qtcreator

Argumentos de comando: instalar

../../../../_images/image07.jpeg

You are almost ready to build. Just one note: QtCreator will need write permissions on the install prefix. By default (which I am using here) QGIS is going to get installed to /usr/local/. For my purposes on my development machine, I just gave myself write permissions to the /usr/local directory.

Para iniciar la construcción, haga click en el gran ícono de martillo abajo a la izquerda de la ventana.

../../../../_images/image08.jpeg

Estableciendo su ambiente de ejecución

As mentioned above, we cannot run QGIS from directly in the build directly, so we need to create a custom run target to tell QtCreator to run QGIS from the install dir (in my case /usr/local/). To do that, return to the projects configuration screen.

../../../../_images/image04.jpeg

Ahora seleccione la pestaña “Ejecutar Configuración”

../../../../_images/image09.jpeg

Necesitamos actualizar la configuración predeterminada de ejecución de usar la configuración de ejecución “qgis” a usar una personalizada.

../../../../_images/image10.jpeg

Do do that, click the “Add v” combo button next to the Run configuration combo and choose “Custom Executable” from the top of the list.

../../../../_images/image11.jpeg

Ahora en el área de propiedades establezca los siguientes detalles:

Ejecutable: /usr/local/bin/qgis

Argumentos :

Directorio de trabajo: $HOME

Ejecutar en la terminal: [no]

Depurador: C++ [yes]

Qml [no]

Luego haga click en el botón “Renombrar” y dele un nombre que tenga sentido a su ejecutable ej.: “QGIS Instalado”

../../../../_images/image12.jpeg

Ejecución y depuración

Now you are ready to run and debug QGIS. To set a break point, simply open a source file and click in the left column.

../../../../_images/image14.jpeg

Now launch QGIS under the debugger by clicking the icon with a bug on it in the bottom left of the window.

../../../../_images/image13.jpeg