Hands-On GUI Programming with C++ and Qt5
上QQ阅读APP看书,第一时间看更新

Setting up the working environment

Since you have installed the latest version of Qt, let's fire up Qt Creator and start messing around by creating our first project! You should be able to find Qt Creator's shortcut icon either on your desktop or somewhere within your start menu.

Let's look at the steps to set up our environment:

  1. When you first start Qt Creator, you should see the following interface:
  1. Before you start creating your first project, there are several settings that you might want to tweak. Go to the top menu and select Tools | Options. A window that looks something like this will pop up on the screen:
  1. There are quite a number of different categories available on the left of the window. Each category represents a set of options you can set to customize how Qt Creator will look and operate. You may not want to touch the settings at all, but it's good to learn about them first. One of the first settings you might want to change is the Language option, which is available in the Environment category. Qt Creator provides us with an option to switch between different languages. Although it doesn't support all languages, most of the popular ones are available, such as English, French, German, Japanese, Chinese, Russian, and so on. Once you have selected your desired language, click Apply and restart Qt Creator. You must restart Qt Creator in order to see the changes.
  1. The next setting you probably need is the setting for indentation. By default, Qt uses space indentation, in which four spaces will be added to your script whenever you press the Tab key on your keyboard. Some people, like me, prefer tab indentation instead. You can change the indentation setting at C++ category.
Do note that if you are contributing to Qt project's source code, it's required that you use space indentation instead of tabs, which is the coding standard and style of the Qt project.
  1. Under the C++ category, you can find a Copy button located beside the Edit button, somewhere in the top right position. Click it and a new window will pop up.
  2. Insert a code style name of your own, as you can't edit the default built-in coding style. After you have created your own settings, click the Edit button. You can now see the actual Tabs And Indentation settings under the General tab:
  1. Do note that even though there is a Tabs And Indentation setting located at the Text Editor category, I believe it's an old setting that no longer has any effect in Qt Creator. There is also a note written on the UI that says Code indentation is configured in C++ and Qt Quick settings. A possible reason for this is that since Qt Creator now supports both C++ project and QML projects, Qt developers probably felt there was a need to separate the settings into two, so therefore the old setting is no longer valid. I'm pretty sure this section on Text Editor will be deprecated in the near future.
  1. Next, under the Build and Run category, you'll see a tab labeled Kits.
  1. This is where you can set the compile settings for each platform. As you can see from the next screenshot, my Qt does not support desktop build under MSVC (Microsoft Visual Studio Compiler) because I never installed Visual Studio on my computer. Instead, my Qt only supports desktop build under the MinGW (Minimal GNU for Windows) compiler. From this window, you can check and see if your Qt supports the platform and compiler you wanted for your project and make changes to it if necessary. But for now, we'll just leave it as it is. To learn more about what is a kit is and how to configure the build settings, please head over to Chapter 15, Cross-Platform Development:
  1. Finally, we can link our project to our version control server at the Version Control category.
  2. Version control allows you or your team to submit code changes to a centralized system so that each and every team member can obtain the same code without passing files around manually. When you're working in a big team, it's very difficult to manually keep track of the code changes, and even more so to merge the code done by different programmers. Version control systems are designed to solve these issues. Qt supports different types of version control systems, such as Git, SVN, Mercurial, Perforce, and so on. Although this is a very useful feature, especially if you're working in a team, we don't need to configure it for now: