Deploying a Qt application on Windows?

那年仲夏 提交于 2019-12-13 14:24:40

问题


I'm new to Qt and cannot figure out how to deploy a simple Qt application on Windows. It runs fine when run from inside Qt Creator, but it won't run when directly executed. I have the newest version of the Qt SDK installed and am using all of the default settings.

I have read dozens of "how to" guides, all of which provided conflicting information, in addition to dozens upon dozens of forum threads, blog posts, and questions on here. I simply cannot find instructions that clearly explain how to deploy a Qt application on Windows.

I tried putting all the DLLs I could find in the application directory, but that didn't work. I also tried building Qt statically, but that didn't work either.

Can anyone help me out?

EDIT: Thank you both for your replies. Here is some additional information:

I am using "Qt Creator 2.4.1, Based on Qt 4.7.4"

I have the following includes across different files:

#include <QtGui/QApplication>
#include <QDebug>
#include <QTextEdit>
#include <QtGui>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include "qthread.h"
#include "windows.h"
#include <QMessageBox>

I'm using the default compiler that came with Qt, MinGW.


回答1:


First of all, please post the details like

Which qt version you are working on? What modules are you using - QtNetwork, QTGui etc ?

Lastly what compiler are you using, MinGW, MSVC ?

All you need to do is deploy QTCore dll and other dlls for modules you have included in your project in the application directory.

Further, if you are using MSVC compiler, you will have to deploy MSVC runtime. You can find the redistributable on the microsoft website.

Alternatively if you are using mingw then you might need to deploy proper g++ runtime.

If you are still unable to deploy the application with above information, provide the additional details so I can suggest the correct way.




回答2:


The simple solution is to include the Qt dlls with your deployment, placing them in the same location as the executable. Be aware that Qt uses different dlls for release vs. debug builds, so don't accidentally deploy a debug build.

Using static libraries is also viable. Your edit states you've tried both static and same-directory deployment. If neither of these (especially the static build) are working, you're doing something seriously wrong and it's rather difficult to debug over a board like SO.



来源:https://stackoverflow.com/questions/12774724/deploying-a-qt-application-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!