How to turn Visual Studio engineering into a QT project

Source: Internet
Author: User


I am a QT novice, but there is a need on the recent project to turn the original Visual Studio project into Qt Creator project. After some research and hands-on practice and re-study and practice, this conversion has finally been successfully completed and is hereby recorded.



Environment:



-Visual Studio (Ultimate)



-QT 5.5 Community



-The original VS project is a build DLL project



-The original VS project is actually based on the QT template project



(with Qt's vs plugin installed, you can build a QT template-based project in VS.) But there's another story here. For Visual Studio 2013, the plug-in (add-in) is no longer the recommended way, and the recommended way is called package or extension. So once you install the QT plug-in (often 2012 version), and then want to uninstall it is extremely difficult, and even MSDN did not write a very clear solution, and the online solution is mostly to modify the registry, the author did not try, I do not know whether to uninstall clean. )






First introduce the features of QT Engineering. Compared to the VS,QT project document is very simple, is a. Pro file, of course, sometimes there are. pri files and. pro.user files: The purpose of the pro file is to implement cross platform, that is, across platforms. The contents of the pro file are configuration information, For example, the location of the header file, the library file, the library filename, the target file name, and so on.. pri files are also a. Pro file, just because it is assumed to be part of a. Pro file, so called. PRI and not called. Pro file. In my case, the. pri file is primarily headers and sources, respectively, representing the header and source files. Finally, the. pro.user file is an XML file that is automatically generated and is primarily recorded for the configuration information of the project in Qt Creator, including some system environment variables.



There are a lot of good articles on the web and how to write the. Pro file. Links to several articles are as follows:


10 minutes Learn Qmake qmake Tutorial Qmake concept qmake Advanced Concept qmake Command reference an article that has turned over all the articles above to talk about. Pro file when it comes to qmake, then what is it? Why is the. Pro file written for cross-platform? Originally, Qmake was a tool created by Trolltech Corporation (acquired by Nokia in 2008) to write makefile for different platforms and compilers. Handwritten makefile are difficult and error-prone, especially when you need to write several makefile for different platforms and compiler combinations. Using Qmake, the developer creates a simple "project" file (i.e.. pro file) and runs qmake to generate the appropriate makefile. Qmake will pay attention to the dependencies of all compilers and platforms, freeing developers to care only about their code. Trolltech Company uses Qmake as the primary tool for the QT Library and QT-provided tools.

Now that you understand the qmake and. Pro file, take a look at my conversion history.
The first step, because the original Visual Studio project is based on the QT template project, so we can use the QT plugin in vs "Create Basic. Pro file ..." menu option to automatically generate a. Pro file, in fact, not only the. Pro file is generated, but also the. pri file is generated. However, the current. Pro file is still not available because there are a number of configurations that need to be modified, such as Includepath and Libs.
The second step is to modify the. Pro file to contain the correct and necessary configuration information. To summarize the author's specific changes to the. Pro file are as follows: 1. TEMPLATE = Lib 2. Change DESTDIR = xxx to: Release:destdir = xxx/release Debug:destdir = Xxx/debug 3. CONFIG + = Debug_and_release 4. Perfect Includepath 5. Perfect Dependpath (here again has the story: afterwards the author found, as long as in Libs wrote the-L "<LIBPATH>", there is no need to write Dependpath. ) 6. Plus Release:dependpath and Debug:dependpath 7. Similarly, perfect LIBS, add release:libs and Debug:libs
In the third step, double-click on the modified. Pro file, QT creator open the project, select the appropriate kit, and you are ready to build.  Because it is a 64-bit machine, Kit chose Qt 5.5.1 's msvc2013_64. Finally, it is important to note that in the system environment variable%path%, for Visual Studio compiler Cl.exe and linker link.exe, the alignment path is selected. For example, for a 64-bit machine, the path C:\Program files (x86) \microsoft Visual Studio 12.0\vc\bin\amd64 should be added to%path% instead of C:\Program Files (x86) \ Microsoft Visual Studio 12.0\vc\bin This article is detailed in the previous blog post.
After completing the above steps, you can successfully build in Qt creator. The last thing to remind you is that if you change the. Pro file and want the changes to take effect, you must manually delete the qmake generated Makefile, Makefile.debug, and makefile.release files.
Here is an example of a. Pro file:

TEMPLATE = lib
TARGET = MyProject
Release:DESTDIR = ../../../Output/x64/Release
Debug:DESTDIR = ../../../Output/x64/Debug
QT += core qml
CONFIG += debug_and_release
DEFINES += WIN64 QT_DLL QT_QML_LIB MyProject_LIB

INCLUDEPATH += ./GeneratedFiles \
    . \
    ./GeneratedFiles/Release \
    $$(VC_INCLUDE) \
    $$(VC_INCLUDE)/../atlmfc/include \
    $$(WINSDK_INCLUDE)/shared \
    $$(WINSDK_INCLUDE)/um

DEPENDPATH += . \
    $$(WINSDK_LIB)/um/x64 \
    $$(VC_LIB)/amd64 \
    $$(QTDIR)/lib \
    $$(QTDIR)/bin \

Release:DEPENDPATH +=  ../../../3rd_library/opencv/libs/Release/x64 \
    ../../../3rd_library/DirectShow/baseclasses/x64/Release

Debug:DEPENDPATH += ../../../3rd_library/opencv/libs/Debug/x64 \
    ../../../3rd_library/DirectShow/baseclasses/x64/Debug

MOC_DIR += ./GeneratedFiles/release
OBJECTS_DIR += release
UI_DIR += ./GeneratedFiles
RCC_DIR += ./GeneratedFiles

Release:LIBS += -L"../../../3rd_library/DirectShow/baseclasses/x64/Release" \
    -lstrmbase \
    -L"../../../3rd_library/opencv/libs/Release/x64" \
    -lqtmain \
    -lQt5Qml \
    -lQt5Core \
    -lopencv_calib3d248 \
    -lopencv_contrib248 \
    -lopencv_core248 \
    -lopencv_features2d248 \
    -lopencv_flann248 \
    -lopencv_gpu248 \
    -lopencv_highgui248 \
    -lopencv_imgproc248 \
    -lopencv_legacy248 \
    -lopencv_ml248 \
    -lopencv_nonfree248 \
    -lopencv_objdetect248 \
    -lopencv_ocl248 \
    -lopencv_photo248 \
    -lopencv_stitching248 \
    -lopencv_superres248 \
    -lopencv_ts248 \
    -lopencv_video248 \
    -lopencv_videostab248

Debug:LIBS += -L"../../../3rd_library/DirectShow/baseclasses/x64/Debug" \
    -lstrmbasd \
    -L"../../../3rd_library/opencv/libs/Debug/x64" \
    -lqtmaind \
    -lQt5Qmld \
    -lQt5Cored \
    -lopencv_calib3d248d \
    -lopencv_contrib248d \
    -lopencv_core248d \
    -lopencv_features2d248d \
    -lopencv_flann248d \
    -lopencv_gpu248d \
    -lopencv_highgui248d \
    -lopencv_imgproc248d \
    -lopencv_legacy248d \
    -lopencv_ml248d \
    -lopencv_nonfree248d \
    -lopencv_objdetect248d \
    -lopencv_ocl248d \
    -lopencv_photo248d \
    -lopencv_stitching248d \
    -lopencv_superres248d \
    -lopencv_ts248d \
    -lopencv_video248d \
    -lopencv_videostab248d

LIBS += -L"$$(WINSDK_LIB)/um/x64" \
    -L"$$(VC_LIB)/amd64" \
    -L"$$(QTDIR)/lib" \
    -L"$$(QTDIR)/bin" \
    -lWtsapi32 \
    -lPathcch \
    -l3DScanningEngine \
    -lUserenv \
    -lwinmm \
    -lMf \
    -lMfplat

include(MyProject.pri)

In the actual build process, the author also found that Qt is called Jom.exe to do. What is this? It turns out that in VS, there is a tool called NMAKE, which is much like the make on Linux. But this NMAKE has a drawback (I'm not sure there's a downside now, but in 2009), it's not possible to use multi-core advantages of parallel compilation. So, someone wrote a tool called Jom, similar to the multithreaded version of NMAKE. The original article about Jom is here: http://blog.qt.io/blog/2009/03/27/speeding-up-visual-c-qt-builds/







Related Article

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.