Qt Creator
While a detailed overview of Qt Creator is beyond the scope of this book (the Qt Creator manual is accessible via the Help mode as described here), it’s worth having a quick whistle stop tour before we get stuck to our first project, so launch the freshly installed application and we’ll take a look:
At the upper left-hand side (1) are the different areas or modes of the application:
- Welcome mode is the default when Qt Creator is launched and is the jumping off point to create or open projects. There is an extensive set of examples that help showcase the various capabilities of the framework as well as a selection of tutorial videos.
- Edit mode is where you will be spending the vast majority of your time and is used for editing all the various text-based files.
- Design is accessible only when you have a UI file open and is a WYSIWYG editor for views. Although useful for UX design and basic layout work, it can get frustrating quite quickly and we will do all of our QML work in Edit mode instead. Working this way promotes understanding of the QML (as you have to write it) and also has the advantage that the editor is not adding code that you don’t want.
- Debug mode is used for debugging applications and is beyond the scope of this book.
- Projects mode is where configuration for the project is managed, including the build settings. Changes made here will be reflected in the *.pro.user file.
- Help mode takes you to the Qt Creator manual and Qt library reference.
Below that, we have the build/run tools (2):
- Kit/Build lets you select your kit and set the build mode
- Run builds and runs the application without debugging
- Start Debugging builds and runs the application with a debugger (note that you must have a debugger installed and configured in your selected kit for this to work)
- Build Project builds the application without running it
Along the bottom (3), we have a search box and then several output windows:
Issues displays any warnings or errors. For compiler errors relating to your code, double-clicking on the item will navigate you to the relevant source code.
- Search Results lets you find occurrences of text within various scopes. Ctrl + F brings up a quick search, and from there selecting Advanced… also brings up the Search Results console.
- Application Output is the console window; all output from application code like std:: cout and Qt’s equivalent qDebug() appears here, along with certain messages from the Qt framework.
- Compile Output contains output from the build process, from qmake through to compilation and linking.
- Debugger Console contains debugging information that we won’t be covering in this book.
- General Messages contains other miscellaneous output, the most useful of which is from qmake parsing of *.pro files, which we will look at later.
The search box really is a hidden gem and saves you from clicking through endless files and folders trying to find what you are looking for. You can start typing the name of a file you are looking for in the box and a filtered list appears with all matching files. Simply click on the file you want, and it opens in the editor. Not only that, there are a large number of filters you can apply too. Click your cursor in the empty search box and it displays a list of available filters. The filter m, for example, searches for C++ methods. So, say you remember writing a method called SomeAmazingFunction() but can't remember where it is, just head over to the search box, start typing m Some, and it will appear in the filtered list.
In Edit mode, the layout changes slightly and some new panes appear. Initially, they will be empty, but once you have a project open, they will resemble the following:
Next to the navigation bar is the project explorer, which you can use to navigate the files and folders of your solution. The lower pane is a list of all of the documents you currently have open. The larger area to the right is the editor pane where you write your code and edit documents.
Double-clicking on a file in the project explorer will generally open it in the editor pane and add it to the open documents list. Clicking on a document in the open documents list will activate it in the editor pane, while clicking on the small x to the right of the filename closes it.
Panes can be changed to display different information, resized, split, closed, and possibly filtered or synchronized with the editor using the buttons in the headers. Experiment to get a feel for what they can do.
As you would expect with a modern IDE, the look and feel of the chrome and the text editor is very customizable. Select Tools > Options… to see what is available. I generally edit the following:
- Environment > Interface > Theme > Flat
- Text Editor > Fonts & Colors > Color Scheme > My own scheme
- Text Editor > Completion > Surround text selection with brackets > Off
- Text Editor > Completion > Surround text selection with quotes > Off
- C++ > Code Style > Current Settings > Copy… then Edit…
- Edit Code Style > Pointers and References > Bind to Type name > On (other options Off)
Play around and get things how you like them.