一、先来看一篇转载文章《在 VS2015 中使用 Qt4》
tangzx.qiniudn.com/post-0111-q… 最早的原文,看不到了
github.com/district10/… 原作者的github,里面的东东都下载不了了
二、firecat本人的教程
0、Qt官方
Qt4.8.7官方源码下载
官网的exe只提供了MSVC2010,没有更高版本的。高版本需要自己下载源码编译。
源码里面的配置文件已经提供了MSVC 2015的编译选项,\qt-everywhere-opensource-src-4.8.7\mkspecs\win32-msvc2015
参照官方提供的编译文档一步一步执行即可;但是配置文件里没有提供MSVC 2017的编译选项。
官方编译的文档
1、Qt 4.8.7+MSVC 2017
推荐使用第三方提供的源码,它已经是修改好的,里面含有MSVC 2017编译选项,可以编译。
github.com/scharsig/Qt Qt4.8.7+MSVC2017源码
forum.qt.io/topic/91623… Qt4.8.7+MSVC2017论坛
github.com/sandym/qt-p… 仅供参考,编译补丁
github.com/Homebrew/fo… 仅供参考,编译补丁
github.com/BartVandewo… 仅供参考,编译补丁
完整的编译过程:
下载第三方源码github.com/scharsig/Qt… 然后解压
---step1---
Windows桌面-开始-程序-Visual Studio 2017-Visual Studio Tools-VC-x86 Native Tools Command Prompt for VS 2017
---step2---
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise>cd F:\Qt\setup-exe\4.8.7\Qt-master\qt-4.8.7-vs2017
---step3---
F:\Qt\setup-exe\4.8.7\Qt-master\qt-4.8.7-vs2017>configure -help
---step4---
F:\Qt\setup-exe\4.8.7\Qt-master\qt-4.8.7-vs2017>
configure -make nmake -debug-and-release -opensource -confirm-license -platform win32-msvc2017 -prefix F:\Qt\Qt4.8.7-msvc2017 -nomake examples -nomake tests
如果不想编译这么多功能模块,可以精简为:
configure -make nmake -debug-and-release -opensource -confirm-license -platform win32-msvc2017 -prefix F:\Qt\Qt4.8.7-msvc2017 \
-no-qt3support -no-multimedia \
-no-audio-backend -no-phonon -no-phonon-backend -no-libtiff \
-no-libmng -no-dbus -no-nis -nomake examples -nomake tests
-release Compile and link Qt with debugging turned off.
-debug Compile and link Qt with debugging turned on.
-nomake tests Disable building of tests to speed up compilation
-nomake examples Disable building of examples to speed up compilation
-confirm-license Automatically acknowledge the LGPL 2.1 license.
---step5---
F:\Qt\setup-exe\4.8.7\Qt-master\qt-4.8.7-vs2017>nmake
---step6---
F:\Qt\setup-exe\4.8.7\Qt-master\qt-4.8.7-vs2017>nmake install
---step7---
添加到Qt Creator
---step8---
新建项目测试,Qt Creator+Qt4.8.7+MSVC2017编译项目时,如果报错:
intermediate\moc\moc_rs_actionzoompan.cpp:-1: error: C1041: 无法打开程序数据库“F:\CADCAM\QCAD\src\build-LibreCAD-v1.0.4-qt4-Desktop_Qt_4_8_7_MSVC2017_32bit-Debug\librecad\vc140.pdb”;如果要将多个 CL.EXE 写入同一个 .PDB 文件,请使用 /FS
解决办法:
在Qt Creator的项目文件,即.pro文件中,可以通过QMAKE_CXXFLAGS来给MSVC编译器传递编译开关。
QMAKE_CXXFLAGS += /FS
CONFIG += c++11 #C++11标准
#QMAKE_CXXFLAGS_DEBUG += -std=c++11 #在pro文件失效
#QMAKE_CXXFLAGS += -std=c++11 #在pro文件失效
QMAKE_CXXFLAGS += /FS #firecat add
win32-msvc*:QMAKE_CXXFLAGS += /wd"4819" #去掉C4819的警告
QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO -= -Zc:strictStrings #当在Debug模式下正常编译通过,但在Release模式下报C2440的错误,原因是Wbemidl.h这个头文件中有初始化非const的字符数组的写法
MSVC 2017编译器常见错误的解决:
docs.microsoft.com/en-us/cpp/e…
2、Mac OS+Qt 4.8.7
笔者的Mac OS版本是MacOS-10.15-Catalina,高版本的OS和Clang已经不再支持Qt官方发布的Qt4了。
解决办法可以参见我的另一篇博文:blog.csdn.net/libaineu200…
trac.macports.org/ticket/5865… mac下编译qt4遇到问题
github.com/macports/ma… mac编译补丁