C++ 如何在其他计算机上运行 Qt 5 应用程序 (Windows 7)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16198649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 20:08:47  来源:igfitidea点击:

How to run Qt 5 applications on other computers (Windows 7)

c++windowsqtdllwindows-7-x64

提问by Narek

I have developed a simple application with Qt 5.0.2 on Windows 7 Ultimate. As a compiler the QtCreator used MSVC2012_64bit. And I cannot move my application onto other computer. It does not work. Qt application requires DLLs that I can't find. The dependency explorer thinks that the .dlls below are not found. Where I can find them? Why is this problem so wide spreaded? All the people complain that they can not get their .exe, which is developed with Qt, work on other computer . enter image description here

我在 Windows 7 Ultimate 上使用 Qt 5.0.2 开发了一个简单的应用程序。作为编译器,QtCreator 使用 MSVC2012_64 位。而且我无法将我的应用程序移动到其他计算机上。这是行不通的。Qt 应用程序需要我找不到的 DLL。依赖浏览器认为.dll没有找到下面的s。我在哪里可以找到它们?为什么这个问题如此广泛?所有的人都抱怨他们不能让他们.exe用 Qt 开发的,在其他计算机上工作。 在此处输入图片说明

EDIT1:BTW when I have added DCOMP.dlldownloaded from the internet, the not found dlls become 2-3 times more than it is now :)

EDIT1:顺便说一句,当我添加了DCOMP.dll从互联网上下载的文件时,未找到的 dll 比现在多 2-3 倍:)

EDIT2:Also note that on other computer (Windows 7 Home Premium) when I double click on the exe file, it shows that it loades and no effect, no error nothing at all.

EDIT2:另请注意,在其他计算机(Windows 7 家庭高级版)上,当我双击 exe 文件时,它显示它已加载并且没有效果,根本没有任何错误。

采纳答案by Narek

This the list of dlls I needed and also I have copied the C:\Qt\Qt5.0.2\5.0.2\mingw47_32\plugins\platformsfolder:

这是我需要的 dll 列表,并且我已经复制了该C:\Qt\Qt5.0.2\5.0.2\mingw47_32\plugins\platforms文件夹:

enter image description here

在此处输入图片说明

Just this and it worked for me. BTW I use Windows 7 Ultimate 64x, and Qt 5.0.2 for Windows 32-bit (MinGW 4.7, 650 MB) package for Qt.

只是这个,它对我有用。顺便说一句,我使用 Windows 7 Ultimate 64x 和 Qt 5.0.2 for Windows 32-bit (MinGW 4.7, 650 MB) package for Qt。

EDIT: You might also need QtCreator's .dll to be copied and also you might need to have a file named qt.confwith the following content (copied from @Renato answer):

编辑:您可能还需要复制 QtCreator 的 .dll 并且您可能需要有一个以qt.conf以下内容命名的文件(从@Renato 回答中复制):

[Paths]

Libraries=./platforms

回答by Renato

just add the file qt.confto your app dir with the following content

只需qt.conf使用以下内容将文件添加到您的应用程序目录

[Paths]

Libraries=./platforms

then copy, to same app dir, the subdir "platforms" that you will find into dir C:\Qt\Qt5.1.1\Tools\QtCreator\bin

然后将子目录“平台”复制到相同的应用程序目录,您将在目录 C:\Qt\Qt5.1.1\Tools\QtCreator\bin 中找到

That's all.

就这样。

This solves because qtcore.dll is compiled with internal paths of your qt instalation. (I dont know wy !). Since, qt.conf is allways read by qtcore when the app starts the librarys in "platforms" will be included and the app works at all on anyone host.

这可以解决,因为 qtcore.dll 是使用 qt 安装的内部路径编译的。(我不知道为什么!)。因为,当应用程序启动时,qtcore 始终会读取 qt.conf,“平台”中的库将被包含在内,并且该应用程序可以在任何主机上运行。

Warning: the qtcore and platforms sub dir have to became from the same qt instalation.

警告:qtcore 和平台子目录必须来自同一个 qt 安装。

Sorry by the English but the solution works fine.

英语很抱歉,但解决方案工作正常。

回答by keithzg

Qt these days (as of at least Qt 5.2, if not earlier) ships with "windeployqt.exe", which when pointed at your compiled program (and, if like me you're using them, as an additional argument of "--qmldir path/to/QML/files" for a Qt Quick program) should spit out all the required DLLs into the same directory as your compiled program currently resides. So for myself on a local build machine for example, I ran something along the lines of:

如今的 Qt(至少从 Qt 5.2 开始,如果不是更早的话)附带了“windeployqt.exe”,当指向您编译的程序时(并且,如果像我一样,您正在使用它们,作为“-- qmldir path/to/QML/files”(用于 Qt Quick 程序)应该将所有必需的 DLL 输出到与您编译的程序当前所在的目录相同的目录中。例如,对于我自己在本地构建机器上,我运行了以下内容:

    windeployqt --qmldir C:\Code\AppSource C:\Code\build-msvc2010\release

This is with the Qt \bin directory in my $PATH (or, I guess in Windows parlance, %PATH% ;)) using Qt 5.5, although I've done the same back with 5.2 and 5.3 as well.

这是使用 Qt 5.5 的我的 $PATH 中的 Qt \bin 目录(或者,我猜用 Windows 的说法是 %PATH% ;)),尽管我在 5.2 和 5.3 中也做了同样的事情。

IIRC if using MSVC as the compiler I still needed to copy those DLLs (in my case, msvc2010, so msvcp100.dll and msvcr100.dll) manually, but I could be remembering wrong.

IIRC 如果使用 MSVC 作为编译器,我仍然需要手动复制这些 DLL(在我的情况下,msvc2010,所以 msvcp100.dll 和 msvcr100.dll),但我可能记错了。

回答by Daan

Thanks for your help folks!

谢谢大家的帮助!

For me, just adding qwindows.dllto the /platformsdirectory somehow didn't cut it.
I finally got everything to work by bluntly copying the entire pluginsdirectory to my application's binary directory and creating a qt.conffile with the following content:

对我来说,只是添加qwindows.dll/platforms目录不知何故并没有削减它。
通过直接将整个插件目录复制到我的应用程序的二进制目录并创建一个qt.conf包含以下内容的文件,我终于让一切正常工作:

[Paths]
Plugins=./plugins