VS+QT和qtcreator工程的互相转换
QT Creator的project轉成Visual Studio的project
在windows下,運行Qt Command Prompt。
輸入命令行:
qmake -tp vc XXX.pro
會生成文件XXX.vcxproj
Visual Studio的project轉成QT Creator的project
第一步,因為原Visual Studio工程就是基于QT Template的工程,所以我們可以用VS里的QT插件里的"Create basic .pro file..."菜單選項來自動生成一個.pro文件,實際上,不僅僅生成了.pro 文件,還生成了.pri文件。但是目前的.pro文件還是不能用的,因為其中還有大量的配置需要修改,比如INCLUDEPATH和LIBS.
第二步,修改.pro文件使其包含正確而必要的配置信息。
總結筆者對.pro文件的具體修改如下:
1. TEMPLATE = lib
2. 將DESTDIR =? xxx改成:
??? Release:DESTDIR = xxx/Release
??? Debug:DESTDIR = xxx/Debug
3. CONFIG += debug_and_release
4. 完善INCLUDEPATH
5. 完善DEPENDPATH (這里又有故事了:事后筆者發現,只要在LIBS里寫了-L"<LIBPATH>",就沒必要寫DEPENDPATH了。)
6. 加上 Release:DEPENDPATH 和 Debug:DEPENDPATH
7. 類似的,完善LIBS,添加Release:LIBS和Debug:LIBS
第三步,雙擊改好的.pro文件,QT Creator打開此工程,選中合適的Kit,就可以build了。因為是64位機器,Kit選的是QT 5.5.1的msvc2013_64.
最后千萬要注意的是,在系統環境變量%PATH%里,對于Visual Studio的編譯器cl.exe和鏈接器link.exe, 要選對路徑。比如,對于64位的機器,路徑 C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64 應該被加到%PATH%中,而不是 C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin 這一條在前一篇博文中已有詳細闡述。
以上步驟做完后,就可以順利地在QT Creator中進行build了。
最后還要提醒的一點是,如果更改了.pro文件,想讓更改生效,必須手動刪除qmake生成的Makefile, Makefile.Debug和Makefile.Release文件。
下面是一個.pro文件的實例:
[plain] view plain copy
??? 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)?
總結
以上是生活随笔為你收集整理的VS+QT和qtcreator工程的互相转换的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt工程转换成VS工程
- 下一篇: 用OpenGL进行曲线、曲面的绘制