Learn Qt 5
上QQ阅读APP看书,第一时间看更新

Project creation

In the previous chapter, we saw how easy it is to set up a new project just by creating a few text files. However, we’ll create our new solution using Qt Creator.  We will use the new project wizard to guide us through creating a top-level solution and a single subproject.

From the top menu, select File > New File or Project and then Projects > Other Project > Subdirs Project and click on Choose…:

Subdirs Project is the template we need for our top-level solution project. Give it the name cm and create it in our qt projects folder:

On the Kit Selection pane, check the Desktop Qt 5.10.0 MinGW 32bit kit we installed. Feel free to select additional kits you want to try out if you have them installed, but it’s not necessary. Click on Next:

As discussed, version control is beyond the scope of this book, so in the Project Management pane, select None from the Add to version control dropdown. Click on Finish & Add Subproject:

We’ll add the user interface project as the first subproject. The wizard follows more or less the same pattern as the steps we've just followed, so perform the following:

  1. Select Projects > Application > Qt Quick Application - Empty and click on Choose...
  2. In the Project Location dialog, give it the name cm-ui (for Client Management - User Interface), leave the location as our new cm folder, and click on Next.
  3. In the Define Build System dialog, select the build system qmake and click on Next.
  4. In the Define Project Details dialog, leave the default minimal Qt version of QT 5.9 and the Use Qt Virtual Keyboard box unchecked then click on Next.
  5. In the Kit Selection dialog, pick the Desktop Qt 5.10.0 MinGW 32bit kit plus any other kits you wish to try and click on Next.
  6. Finally, in the Project Management dialog, skip version control (leave it as <None>) and click on Finish.

Our top-level solution and UI projects are now up and running, so let’s add the other subprojects. Add the business logic project next, as follows:

  1. In the Projects pane, right-click on the top-level cm folder and select New Subproject….
  2. Select Projects > Library > C++ Library and click on Choose....
  3. In the Introduction and Project Location dialog, pick Shared Library as the Type, name it cm-lib, create it in <Qt Projects>/cm, and then click on Next.
  4. In the Select Required Modules dialog, just accept the default of QtCore and click on Next.
  5. In the Class Information dialog, we get the opportunity to create a new class to get us started. Give the class name Client, with the client.h header file and the client.cpp source file, and then click on Next.
  6. Finally, in the Project Management dialog, skip version control (leave it as <None>) and click on Finish.

Finally, we will repeat the process to create our unit testing project:

  1. New Subproject....
  2. Projects > Other Project > Qt Unit Test.
  3. Project name cm-tests.
  4. Include QtCore and QtTest.
  1. Create the ClientTests test class with the testCase1 test slot and the client-tests.cpp filename. Set the Type as Test and check Generate initialization and cleanup code.
  2. Skip version control and Finish.

That was a lot of dialog boxes to get through, but we’ve now got our skeleton solution in place. Your project folders should look as follows:

We’ll now take a look at each project in turn and make some tweaks before we start adding our content.