IDE - QtCreator
QtCreator is an IDE (Integrated Development Environment) for C++. It provides natively- - color encoding
- - code completion: automatic proposition of possible variable names, class methods, and show expected function arguments
- - quick navigation through hierarchy of files: Use CTRL + left click on a variable or function to go to its declaration, or on include file to go to navigate to the corresponding one. Pressing F4 navigates between header (.hpp) and source (.cpp) files.
- - debugger (visualizing line by line the status of all your variables), as well as a profiler.
QtCreator is able to load a complete project only from the generic CMakeLists.txt configuration file which is already provided. Editing a project with QtCreator doesn't impact the source files.
Note: Do not confuse the IDE QtCreator, and the library Qt.- - QtCreator is an IDE, while Qt is a library/framework to develop GUI interfaces.
- - Using QtCreator to edit your code does not mean that you are using the library Qt - For instance, CGP it totally independant of Qt.
- - Conversely, you can code with the library Qt without using QtCreator.
Load project in QtCreator
In Linux, you can either
- - open a command line on the "root directory" (= the directory that contains the file CMakeLists.txt -- to be adapted depending on the project) and type
qtcreator CmakeLists.txt &
- - or start QtCreator from you application startup panel and then follow
-
- File -> Open File or Project -> [look for the file CMakeLists.txt]
In MacOS you will have to open QtCreator from your launchpad and then follow
-
File -> Open File or Project -> [look for the file CMakeLists.txt]
Whichever method you use, QtCreator should propose to configure the project. Once it is done, you will have access to the hierarchy of files from the left panel.
Compiling the code
The code can be compiled using the small hammer icon on the bottom left, or using the key shortcut: CTRL+b
If the icon is not selectable, you may have to explicitly set the mode "RelWithDebInfo" Build type to be able to run the compilation on the screen-like window above the right arrow.Executing the code
The code can be executed using the green arrow icon on the bottom left, or using the key shortcut: CTRL+r
- the shortcut CTRL+r also runs the compilation if needed.
The path of the run directory should be set to the root directory otherwise will stop with an error message will indicate that the shader or data file cannot be read (shown in the following image).
To this end
- - Go to Projects (left panel)
- - On the panel (Build & Run) select Run
- - Observe the `Working Directory` entry and set it to the root path of the library
Explanations
- - The code expect to read some external files (shader files, textures, etc.) from the scenes/[current_dir] directory (directory that contains the file CMakeLists.txt). The relative path of these files are directly encoded within the code.
- - The executable should be run from a directory able to access these asset files from the same relative path.
- - By default, the executable is run from the temporary parent directory in QtCreator where the executable binary is generated. So the program cannot access to the asset files. This `working directory` should therefore being changed.
Automatic completion
Once the project is loaded, automatic completion will appear automatically and help you write code and use the library.
Files navigation
In addition to the file hierarchy from the left panel, you can use `CTRL+left click` on element of code to navigate through the code.
- CTRL+left click on a type goes to the type definition (useful to understand the library).
- CTRL+left click on a function goes to its definition.
- F4 switch between the header (.hpp) and implementation (.cpp) file. (useful to switch between public signature of a function/class and its implementation).
- CTRL+left click on a variable goes to its declaration.
- CTRL+left click on a #include [path] navigate to this header file.
Common issue to load a project with QtCreator
When QtCreator fails to load your project it is often caused by conflicting temporary files.
In some other cases the project may load but the executable file is not found.
- - Everytime QtCreator load a project, it generates temporary files
-
- - CMakeListst.txt.user (in the current directory)
- - An entire temporary directory: build-XX-Desktop-Default in the parent directory.
- - If you have failed previous attempt to open QtCreator, or if you moved your project directory to another place (or to another computer), these temporary files are not anymore coherent.
- - You can safely delete this temporary files (CMakeListst.txt.user and the entire directory build-XX-Desktop-Default), and restart the process to open QtCreator.