Chemmy's Blog

chengming0916@outlook.com

一、先来看一篇转载文章《在 VS2015 中使用 Qt4

http://tangzx.qiniudn.com/post-0111-qt4-vs2015.html 最早的原文,看不到了

https://github.com/district10/qt4-vs2015x64 原作者的github,里面的东东都下载不了了

二、firecat本人的教程

0、Qt官方

Qt4.8.7官方源码下载

https://download.qt.io/new_archive/qt/4.8/4.8.7/

官网的exe只提供了MSVC2010,没有更高版本的。高版本需要自己下载源码编译。

源码里面的配置文件已经提供了MSVC 2015的编译选项,\qt-everywhere-opensource-src-4.8.7\mkspecs\win32-msvc2015

参照官方提供的编译文档一步一步执行即可;但是配置文件里没有提供MSVC 2017的编译选项。

官方编译的文档

https://doc.qt.io/archives/qt-4.8/installation.html

https://doc.qt.io/archives/qt-4.8/configure-options.html

https://doc.qt.io/archives/qt-4.8/install-win.html

https://doc.qt.io/archives/qt-4.8/install-mac.html

https://doc.qt.io/qt-5/build-sources.html

1、Qt 4.8.7+MSVC 2017

推荐使用第三方提供的源码,它已经是修改好的,里面含有MSVC 2017编译选项,可以编译。

https://github.com/scharsig/Qt Qt4.8.7+MSVC2017源码

https://forum.qt.io/topic/91623/building-qt-4-8-7-with-visual-studio-2017 Qt4.8.7+MSVC2017论坛

https://github.com/sandym/qt-patches 仅供参考,编译补丁

https://github.com/Homebrew/formula-patches/tree/master/qt 仅供参考,编译补丁

https://github.com/BartVandewoestyne/qt_4_8_7_with_vs2017_patch 仅供参考,编译补丁

完整的编译过程:

下载第三方源码https://github.com/scharsig/Qt/tree/master/qt-4.8.7-vs2017 然后解压

-–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

![[编译Qt 4.8.7源码/IMG-20250807081809727.png]]

-–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

win32-msvc*:QMAKE_CXXFLAGS += /wd"4819" QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO -= -Zc:strictStrings 

MSVC 2017编译器常见错误的解决:

https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/c-cpp-build-errors?view=vs-2017

2、Mac OS+Qt 4.8.7

笔者的Mac OS版本是MacOS-10.15-Catalina,高版本的OS和Clang已经不再支持Qt官方发布的Qt4了。

解决办法可以参见我的另一篇博文:https://blog.csdn.net/libaineu2004/article/details/104740623

https://trac.macports.org/ticket/58651 mac下编译qt4遇到问题

https://github.com/macports/macports-ports/tree/master/aqua/qt4-mac mac编译补丁

方法1: 为当前用户设置环境变量

为当前用户设置 HTTP_PROXY 和 HTTPS_PROXY 环境变量,Podman 将自动读取这些环境变量并使用代理。

1
2
3
4
5
6
7
8
9
10
11
# Bash
export HTTP_PROXY="http://代理地址:端口"
export HTTPS_PROXY="https://代理地址:端口"

# 对于 bash, 也可以在 ~/.bashrc 中添加上述命令使其永久有效

# Fish
set -x HTTP_PROXY "http://代理地址:端口"
set -x HTTPS_PROXY "https://代理地址:端口"

# 对于 fish,也可以在 ~/.config/fish/config.fish 中添加以上命令

如果代理需要身份验证,可以在 URL 中添加用户名和密码。格式如下:

1
http://用户名:密码@代理地址:端口

方法2:为 Podman 服务设置配置文件

通过编辑 /etc/containers/registries.conf 配置文件为 Podman 服务设置代理。在该文件中添加如下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[registries.search]
registries = ['docker.io', 'quay.io']

[registries.insecure]
registries = []

[registries.block]
registries = []

[registries.unqualified-search-registries]

[registry.mirrors]

[registry.configs]

[registry.configs.REGISTRY_NAME.HOSTNAME/HOSTPATH]
unqualified-search-registries = ["registry.fedoraproject.org", "registry.access.redhat.com", "docker.io"]
blocked=false

[registry.configs.REGISTRY_NAME.HOSTNAME]
http-proxy="http://代理地址:端口"
https-proxy="https://代理地址:端口"

替换 REGISTRY_NAME.HOSTNAME 为您要配置的注册表,如 docker.io。如果代理需要身份验证,则使用类似 http://user:password@proxy.example.com:8080 的格式。

方法3: 为单个 Podman 命令设置代理

为单个 Podman 命令临时设置代理,方法是在命令前添加 –build-arg 参数。例如:

1
podman --build-arg HTTP_PROXY="http://代理地址:端口" --build-arg HTTPS_PROXY="https://代理地址:端口" pull nginx

方法四: 配置 http-proxy.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ systemctl status podman
● podman.service - Podman API Service
Loaded: loaded (/usr/lib/systemd/system/podman.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/podman.service.d
└─http-proxy.conf
Active: inactive (dead) since Mon 2023-11-20 18:45:12 CST; 3 months 22 days ago
Docs: man:podman-system-service(1)
Process: 50669 ExecStart=/usr/bin/podman $LOGGING system service (code=exited, status=0/SUCCESS)
Main PID: 50669 (code=exited, status=0/SUCCESS)

Nov 20 18:45:07 downlaod systemd[1]: Starting Podman API Service...
Nov 20 18:45:07 downlaod systemd[1]: Started Podman API Service.
Nov 20 18:45:07 downlaod podman[50669]: time="2023-11-20T18:45:07+08:00" level=info msg="/usr/bin/podman filtering at log level>
Nov 20 18:45:07 downlaod podman[50669]: time="2023-11-20T18:45:07+08:00" level=info msg="Not using native diff for overlay, thi>
Nov 20 18:45:07 downlaod podman[50669]: time="2023-11-20T18:45:07+08:00" level=info msg="Setting parallel job count to 13"
Nov 20 18:45:07 downlaod podman[50669]: time="2023-11-20T18:45:07+08:00" level=info msg="Using systemd socket activation to det>
Nov 20 18:45:07 downlaod podman[50669]: time="2023-11-20T18:45:07+08:00" level=info msg="API service listening on \"/run/podman>
Nov 20 18:45:12 downlaod systemd[1]: podman.service: Succeeded.

$ cat /etc/systemd/system/podman.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://192.168.21.101:7890"
Environment="HTTPS_PROXY=http://192.168.21.101:7890"
Environment="NO_PROXY=localhost,127.0.0.1,.coding.net,.tencentyun.com,.myqcloud.com,harbor.bsgchina.com"
0%