QT Learning Notes directory structure of 3:QT project

Source: Internet
Author: User

After the first two studies, you can already create your own project using the QT Empty project template. Through this study, to organize the use of QT Engineering directory structure, make the project more standardized and easy to manage. The current directory structure

As shown in the figure, this is the project created in the previous article, only main.cpp and Widget.cpp, widget.h three files, placed directly in a directory, no subdirectories:

When you add a new file to your project, it is automatically created to the current directory by default. Project files are less likely to affect use, but when the file more up, the project becomes difficult to manage, this time, then to tidy up the file becomes troublesome. So, a good project should create a catalog structure for the project when it is first built. Let's look at how to create a directory structure for QT engineering. directory structure using QT engineering

When we need to sub-catalog management files under the project, there are two ways to do this: use the subdirectory path to use the PRI file

Next we introduce these two methods separately, can choose by ourselves. using subdirectory paths

When you add or create a new file to your project, create a sub-file and create the file in a subdirectory.

Place the created class in a subdirectory, and when finished, the effect is as shown in the figure:

The src/widget.h and src/widget.c two files are automatically added to the pro file, using a relative path.
In this way subdirectories, when used, the header file references also add a relative path, otherwise there will be no file errors found. Or, add environment variables to the Pro file:

Includepath + = src

can be used normally. QT Engineering will automatically put the new file classification in the header file and the source file two directories. In the actual directory there are no two folders, but it is particularly awkward to look at. using the PRI file

The second way, use a PRI file. For the use and use of Pro, PRI, PRF, PRL files in Qt, you can learn by yourself.
The role of the PRI file, here is to put a part of the pro file into the PRI file under each path, separately managed, and finally included in the PRI file into pro. How to use:

(1) Create a PRI file manually
Manually create subdirectories and create empty or text files to change the file suffix to pri.
Note that the file name of the PRI file is the subdirectory name displayed by the QT project, rather than the actual manually created subdirectory, it is recommended that the PRI's file name and subdirectory name be consistent.

(2) Include PRI file
Include the PRI file in the pro file, using the Include command

Include (SRC/SRC.PRI)

once saved, the QT Project automatically adds the PRI file to the project and displays subdirectories

(3) Add a new file
Right-Select a subdirectory, click Add New file or create a file, complete as shown below:

The QT project automatically adds files to the PRI project file in the subdirectory and automatically writes the file information to the PRI file.

Using this method, you do not need to increase the INCLUDEPATH environment variable, there is no problem finding the head file. How to remove QT files auto-classify sources and headers

I am currently using the QT version is 5.6, checked the information, found that the latest version when creating or adding files, will automatically classify the files, display sources and headers directory.
There are several ways to get rid of automatic categorization. In the CSDN forum Post asked, is said to be unable to change. It does not affect the use, do not know the subsequent version of this place will not change.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.