Qt 联合Visual Studio编译打包发布

Posted qq_735754647

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Qt 联合Visual Studio编译打包发布相关的知识,希望对你有一定的参考价值。

1、qt

查找项目中使用到的qt动态链接库;

步骤如下

①打开项目使用的windeployqt工具(qt自带的工具);

②进入到文件夹所在目录;使用 cd 命令 

③使用命令:windeployqt Name.exe(在目标文件夹所在目录下执行该命令)

 

但是由于我的QT使用的是MSVC编译器,会用到一些VC的库,使用qt的命令行时会提示我

warning:Cannot find Visual Studio installation directory,VCINSTALLDIR is not set.

解决方案1

win+R,输入QT安装目录下windeployqt.exe的路径,然后空格,再加上项目Release的路径。
我的是:C:\\Qt\\Qt5.13.1\\5.13.1\\msvc2015_64\\bin\\windeployqt.exe D:\\GIICS\\qtReleaseDemo\\x64\\Release\\qtReleaseDemo.exe,供参考。

然后会有这个warning,这个在中间很难被发现,要注意!

找到msvcp140d.dll(我是VS2015,所以是140),复制它的路径添加到环境变量中。我的路径是C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\redist\\debug_nonredist\\x64\\Microsoft.VC140.DebugCRT\\msvcp140d.dll,添加环境变量时,到VC就可以了,后面的不要。

 

 

关闭cmd重新打开(一定要先关闭之前打开的,然后重新打开),输入第三步的路径,C:\\Qt\\Qt5.13.1\\5.13.1\\msvc2015_64\\bin\\windeployqt.exe D:\\GIICS\\qtReleaseDemo\\x64\\Release\\qtReleaseDemo.exe,回车就行了。

看到Release文件夹下多出了QT的很多dll和vcredist_x64.exe就行了。把这个文件夹放到一个全新的计算机也能跑起来,不过得在计算机上先安装图中的vcredist.exe。    

 

方法二

  1. 首先将配置改为Release。

  2. 接下来重新生成项目。

  3. 然后从工程目录/x64/Release/中便可找到生成的exe文件。

  4. 若想运行该exe文件,需将其需要的各个dll文件与其放在同一文件夹中。

    这里主要需要qt的一些dll文件,可在qt安装目录里msvc2017_64/bin文件夹中找到。

使用windeployqt这个命令应该都知道,

将release版本exe复制拷贝到一个单独目录;

4.2打开QT下MSVC 2017控制台,切换到刚才exe所在目录;

4.3再使用 Qt 自带的 windeployqt 工具命令,其语法格式为:

windeployqt 可执行程序名

4.4可以看到windeployqt 工具已经将程序所依赖的qt环境已经复制到当前目录。

还有就是进入VS的安装路径

C:\\ProgramFiles(x86)\\MicrosoftVisualStudio14.0\\Common7\\IDE\\RemoteDebugger\\x64
你是x64开发的就选x64,要不然就选x86.

去把如下运行库拷出来放到exe路径下,要不然去遇到运行库错误,就异常尴尬了!

api-ms-win-core-console-l1-1-0.dll
api-ms-win-core-datetime-l1-1-0.dll
api-ms-win-core-debug-l1-1-0.dll
api-ms-win-core-errorhandling-l1-1-0.dll
api-ms-win-core-file-l1-1-0.dll
api-ms-win-core-file-l1-2-0.dll
api-ms-win-core-file-l2-1-0.dll
api-ms-win-core-handle-l1-1-0.dll
api-ms-win-core-heap-l1-1-0.dll
api-ms-win-core-interlocked-l1-1-0.dll
api-ms-win-core-libraryloader-l1-1-0.dll
api-ms-win-core-localization-l1-2-0.dll
api-ms-win-core-memory-l1-1-0.dll
api-ms-win-core-namedpipe-l1-1-0.dll
api-ms-win-core-processenvironment-l1-1-0.dll
api-ms-win-core-processthreads-l1-1-0.dll
api-ms-win-core-processthreads-l1-1-1.dll
api-ms-win-core-profile-l1-1-0.dll
api-ms-win-core-rtlsupport-l1-1-0.dll
api-ms-win-core-string-l1-1-0.dll
api-ms-win-core-synch-l1-1-0.dll
api-ms-win-core-synch-l1-2-0.dll
api-ms-win-core-sysinfo-l1-1-0.dll
api-ms-win-core-timezone-l1-1-0.dll
api-ms-win-core-util-l1-1-0.dll
api-ms-win-crt-conio-l1-1-0.dll
api-ms-win-crt-convert-l1-1-0.dll
api-ms-win-crt-environment-l1-1-0.dll
api-ms-win-crt-filesystem-l1-1-0.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-locale-l1-1-0.dll
api-ms-win-crt-math-l1-1-0.dll
api-ms-win-crt-multibyte-l1-1-0.dll
api-ms-win-crt-private-l1-1-0.dll
api-ms-win-crt-process-l1-1-0.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-string-l1-1-0.dll
api-ms-win-crt-time-l1-1-0.dll
api-ms-win-crt-utility-l1-1-0.dll
concrt140.dll
msvcp140.dll
ucrtbase.dll
vcruntime140.dll

如遇0xc0000007b,应该是你没把上面这些库放完整。

注意concrt140.dll
msvcp140.dll
vcruntime140.dll(我是VS2015,所以是140)

以上是关于Qt 联合Visual Studio编译打包发布的主要内容,如果未能解决你的问题,请参考以下文章

Qt 联合Visual Studio编译打包发布

Qt - Visual Studio 2013 加载项不会编译项目

Qt 4.8,Visual Studio 2013 编译错误

使用 Visual Studio 构建 qt 项目

带有 qt 的 Visual Studio 无法编译 gui 类

Qt:在 Windows、Visual Studio 2010 (VS2010) 上编译 Qt 5.0.1 时出错