C++ Qt5Widgets.dll 丢失?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16427374/
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
Qt5Widgets.dll is missing?
提问by Patrik Lippojoki
I'm using Qt5 with the Qt Creator.
我在 Qt Creator 中使用 Qt5。
My program works just fine if I launch it from the Qt Creator itself, but if I try to run the .exe
file from debug
or release
folder, I will only get an error:
如果我从 Qt Creator 本身启动它,我的程序就可以正常工作,但是如果我尝试.exe
从debug
或release
文件夹运行文件,我只会得到一个错误:
The program can't start because Qt5Widgets.dll is missing from your computer.
Try reinstalling the program to fix this problem.
I'm new to Qt and have no idea what's causing this, didn't find any decent results from google. I've already tried reinstalling Qt5 (including the creator) but it didn't help.
我是 Qt 的新手,不知道是什么原因造成的,没有从谷歌找到任何像样的结果。我已经尝试重新安装 Qt5(包括创建者),但没有帮助。
My .proj
file looks like this:
我的.proj
文件看起来像这样:
TEMPLATE = app
TARGET = test
QT += \
core \
gui \
widgets \
SOURCES += \
main.cpp
And my main.cpp
looks like this:
我的main.cpp
样子是这样的:
#include <QApplication>
#include <QWidget>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QWidget window();
window.show();
return app.exec();
}
And that's all the code I have.
这就是我拥有的所有代码。
采纳答案by Antwane
When you launch an application built with Qt, you need to have all dll required by Qt modules used in your code (Qt5Widgets.dll, Qt5Core.dll, etc.) in the same folder than your application.
当您启动使用 Qt 构建的应用程序时,您需要将代码中使用的 Qt 模块所需的所有 dll(Qt5Widgets.dll、Qt5Core.dll 等)放在与您的应用程序相同的文件夹中。
You can't use addLibraryPath() for that purpose, because your program must be run before executing this method. And it can't run if it don't find mandatory library in the same folder.
您不能为此目的使用 addLibraryPath(),因为您的程序必须在执行此方法之前运行。如果在同一文件夹中找不到必需的库,则无法运行。
You also need some other libraries to run a Qt5 program depending on the modules you use. Windows specific ones are listed here Statically linked app with QT gives error: Failed to load platform plugin "windows".
您还需要一些其他库来运行 Qt5 程序,具体取决于您使用的模块。此处列出了特定于 Windows 的应用程序与 QT 的静态链接应用程序给出错误:无法加载平台插件 "windows"。
You may also need others libraries: - plugins/qjpeg.dll, etc. if you want to load images files in your GUI. - sqldrivers/qsqlite.dll, etc. if you use database (you need only drivers you use) For these, you can use addLibraryPath() to setup specific locations, but you should avoid this and try as most as possible to put them directly in the right sub-folder near your application.
您可能还需要其他库: - plugins/qjpeg.dll 等,如果您想在 GUI 中加载图像文件。- sqldrivers/qsqlite.dll 等,如果你使用数据库(你只需要你使用的驱动程序)对于这些,你可以使用 addLibraryPath() 来设置特定的位置,但你应该避免这种情况并尽可能地尝试直接放置它们在您的应用程序附近的右侧子文件夹中。
You will find some information about libraries needed by each Qt5 modules on the web. You can also look in your favorite programs install folders to see what libraries are needed by them.
你会在网上找到一些关于每个 Qt5 模块所需的库的信息。您还可以查看您最喜欢的程序安装文件夹以查看它们需要哪些库。
回答by AnatolyS
I hope the following will help you to understand why: http://doc.qt.io/qt-5/deployment.html
我希望以下内容可以帮助您理解原因:http: //doc.qt.io/qt-5/deployment.html