4-point experience in developing QT programs using VS2010 (QT4 to QT5 upgrades, changing sln files, switching qt libraries used by engineering, creating folders in the Solution Explorer view of VS)

Source: Internet
Author: User

Guide

Compared to QT Creator, I prefer to use VS2010 for development. Although the start-up time is relatively slow, but the powerful shortcut keys and the rich plug-ins, as well as the use of many years of experience, make me feel handy in the development process. One of the most important things is that sometimes the Qt creator error is baffling. It is impossible to find the source of the error based on hints. The general error description of VS is more humane, even in some cases can not be solved, but also through the search engine to roughly locate the source of the error. The following is the debugging of some of the source code on the Web, the accumulation of a bit of experience, write down to a memo, and secondly can also be used for yimeimei reference.

The system cannot find the path specified

When I compile from the source code project that I downloaded from the Internet using VS2010, a series of error prompts appear in the output bar:

My development environment is: VS2010 32-bit flagship edition, Windows 7 64-bit, QT library version 5.2.1. The first time I encountered such a problem, it was really baffling. So the Internet search search, found some signs. The project was originally developed using Qt 4.x, but I use QT 5.2.1. So I think it should be a different version of the QT library. A solution was later found in the QT developer community, with the following process:

Locate the. vcxproj file under the project catalog, open and search for keywords:qtversion

Replace with the following:

When you return to VS, you will find the following prompt:

Once you click Reload, you will get the following error message if you start compiling the project directly:

Obviously, we need to configure the QT library version of the project. Because we have changed the QT library version used in the . vcxproj file, we need to configure it in the Qt-vs-addon plugin, select QT Project Settings The following dialog box, select the currently available QT library version ( My version name is msvc2010, and then tick the required modules as shown in the image on the right:

Click OK, and the above error can be eliminated. For projects that are based on other QT versions, they can also be ported as above. The transplant process will need to modify the header file, after all, Qt 4.x and Qt 5.x compared to a larger difference, which is my biggest annoyance when reading the source code of others. Changes are often changed to not want to change, because the issue of the version involved (including QT and VS, and even the third party libraries) too much too torture.

Qt 4.x port to QT 5.x

As mentioned above, if you want to transplant a QT 4.x-based project to QT 5.x, there's a lot more to do. This section is about the Lib file of the Qt library. The above example shows that, when the above error has been modified, the compilation will not be completed successfully, in my machine reported the following error:

The previous compilation work did not error, obviously the connection stage error. Look at the name above, it seems that the QtCored.lib of this file cannot be found. Then, do the following: " click the project name, right-select the project Properties ---configuration properties, type," linker, input, and so on, you can see:

In the Qt installation directory (such as:C:\Qt\Qt5.2.1\5.2.1\msvc2010_opengl\lib), I did not find the above Lib files, and then try to use the corresponding Lib file in the above directory to replace:

Recompile the project, at which point the compilation process is completed and the expected executable program is generated. This is only the Lib file settings, the source code modification is actually another big problem. In particular, Qtgui has disappeared in Qt 5.x, so a large area of file content needs to be modified.

Change the QT library used by the project

When multiple versions of the QT library are installed at the same time in the machine, it is also possible to specify the version to be compiled using the VS. Of course, only the large version of the same situation, because the need to modify the source of the place is small, and even do not need to modify to complete the compilation work. If the big version is different, it is unavoidable to modify the source code.

How do I add a different QT library version to vs? The work will be done by Qt-vs-addin. Select QT options in the menu bar, click the Add button and select the installation path for the QT Library, and the version name can be customized. In the QT default Settings page, you can also specify some of the default settings at compile time.

It is important to note that after the first QT project in VS, if the subsequent addition of different Qt library version, and try to use the new QT Library to compile the project, it is necessary to keep the name of the new QT Library with the name of the QT Library selected to establish the project consistent Otherwise, there will be an incomprehensible error, and perhaps a whole day of groping will not result. Of course, perhaps modifying the. vcxproj file may be useful.

Creating folders in the Solution Explorer view of VS

How do I create a new folder directly in VS and keep it in sync with the file system? It was previously done by creating a new folder in the project directory and then introducing it into the VS engineering view. Although it can be used, it seems too troublesome. The following is a practical approach:

By clicking on the project name in the Solution Explorer view, you can see that there is a small icon appearing on it (the message is: Show All Files ), and when you click on the solution name, the icon disappears. Click on this icon, you can immediately find that the current project directory on the disk all the files appear, including the compilation process produced by the various intermediate files. Obviously, that's what we want! The steps to create a folder are as follows:

Select the name of a good folder, open the project directory, the corresponding folder impressively in the eye! Here are the pre-and post-conditions that I use to organize projects:

Obviously refreshing a lot. The source code file is logically divided, which is helpful for the clear understanding of the whole project's module and architecture. For the later developers and maintenance personnel are a kind of soul of liberation ...

Reference

1. http://qt-project.org/forums/viewthread/24277

Http://www.cnblogs.com/csuftzzk/p/VS_Qt_Experience.html

4-point experience in developing QT programs using VS2010 (QT4 to QT5 upgrades, changing sln files, switching qt libraries used by engineering, creating folders in the Solution Explorer view of VS)

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.