Application Development with Qt Creator(Second Edition)
上QQ阅读APP看书,第一时间看更新

The Projects pane and building your project

You've seen how the .pro file affects your project's compilation, but there's even more to it than this. If you click on the Projects button on the left of Qt Creator, you'll see the project's options, which consist of the following:

  • The Build & Run options
  • The Editor options
  • The Code Style options
  • Dependencies

Each of these is in its own panel.

Note

In most cases, you won't need to monkey around with any of these settings. But you might have to tinker with the Build & Run settings, especially if you're targeting multiple platforms such as Windows and Linux with cross-compilers or Android. (I will write more about this exciting development in Qt later in this book.)

The final thing that you should know is the build and run kit selector. Qt is one of the best cross-platform toolkits available today, and you can easily find yourself working on a system supporting multiple platforms, such as Linux and Android, or multiple versions of Qt. To support this, Qt has the notion of a build kit, which is just the headers, libraries, and associated things to support a specific platform. You can install multiple build kits and choose which build kit you're compiling against by choosing Open Build and Run Kit Selector…. By default, if you followed the steps in the previous chapter to install Qt Creator, you'll have one build kit installed; from the Digia site, you can choose others.

The different types of settings in the Project mode are as follows:

  • For the build settings, there are configuration options for your release and debug builds. In the Build settings editor, you can control whether the build products are placed in their own directory (the default, a so-called shadow build where your build outputs are not mixed with the source code but placed in their own directory), the qmake configuration for the build (and actually see how Qt Creator will invoke qmake), how Qt Creator cleans your project, and any environment variables you need to set for the build.
  • The run settings let you control whether your application runs locally or is deployed on a remote host (not always supported, but usually the case for platforms such as Android), any command-line arguments that you want to pass to your applications, and the settings for the performance analyzer tool, which I will talk about in Chapter 4, Qt Foundations.
  • In the Editor panel, you can set specific editor options for this project. These override the global Qt Creator defaults, which you can set by choosing Options from the Tools menu and selecting the Text Editor option. These options include details such as whether to use tabs or spaces when formatting your code (I strongly suggest you use spaces; it's compatible with editors everywhere!), the number of spaces per tab stop, whether or not automatic indentation should occur, how source files should be encoded, and so forth.
  • The Code Style panel is another override to the global settings for Qt Creator (this time, it's the C++ and Qt Quick panels of the Options dialog available from the Options menu). Here, you can pick the default styles or edit the styles.

    Tip

    I'd strongly recommend that you pick a style that matches the existing source code you're editing; if you're starting from a blank page, the Qt default style is quite readable and is my favorite.

  • The Dependencies panel lets you set the build order if your project file contains multiple subprojects so that things build in the right order. For example, we could choose to open both our library project and our test project; if we do, we'll see the MathFunctions library listed in the dependencies, and we can choose to build the project before the test application is built.