Cannot run my exe file on another computer. “Application requested the runtime to terminate it in an unusual way” error

寵の児 提交于 2019-12-05 02:01:02
It'sPete

More than likely, those computers do not have some required Qt library that your program is using. See the tutorial here: http://doc.qt.io/qt-5/windows-deployment.html

Another easy check would be to install Qt on another computer, move your .exe over and see if it runs. If it does, you certainly did not deploy your application correctly.

Edited to add this helpful link since this seems to be the exact same issue people are seeing: https://bugreports.qt.io/browse/QTBUG-28766

If you have cygwin installed then you can run ldd <your_app.exe> and see list of libraries which are required by your application. After doing so copy your exe to another folder and libraries which are required by it.

This should be OK for LGPL license but I AM NOT A LAWYER so please consult some smarter people which are familiar with legal issues.

You are deploying a mingw compiled application, this requires you to supply the following DLL-Files, additionally to the Qt-DLL's used in your application:

icudt51.dll
icuin51.dll
icuuc51.dll
libstdc++-6.dll (eventually)
platforms/qminimal.dll
platforms/qwindows.dll
libgcc_s_dw2-1.dll (eventually)

Those can be found in your mingw-directory found in your SDK installation.

It is also important the suppied DLL's fit the compiler version.

Timmmm

This is a bug in Qt.

It is because of a missing DLL but it is a plugin DLL so it doesn't show up in depends.exe, and Qt doesn't look for it where it should.

Long story short, if you copy the qwindows.dll (or qwindowsd.dll for debug builds) onto your deployment machine and put in the SAME ABSOLUTE PATH as it came from, i.e. c:\Qt\5.1.0......\mingw48_32\plugins\platforms\qwindows.dll, then your app should work. The presence of a blank qt.conf file in the same directory did not affect things on my development machine but it did STOP the app from working on my deployment machine.

See this comment/bug report for more information: https://bugreports.qt.io/browse/QTBUG-28766?focusedCommentId=216317&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-216317

This is a bug on Windows:

https://bugreports.qt-project.org/browse/QTBUG-28766

Specifically, Qt only looks for qwindows.dll (which is required despite what depends.exe says - it is dynamically loaded) in the hard-coded absolute path that it is installed in on your development machine, i.e. c:\Qt\.....\plugins\platforms. There is a file called qt.conf which you are supposed to be able to use to change the search paths but it does not work.

Fortunately Joost Bloemen came up with a workaround in that bug report:

...

#include <windows.h>
#include <QFileInfo>

int main(int argc, char* argv[])
{
    // Bug workaround. See https://bugreports.qt-project.org/browse/QTBUG-28766
    wchar_t dirpath[MAX_PATH];
    GetModuleFileName(0, dirpath, MAX_PATH);
    QFileInfo dir(QString::fromWCharArray(dirpath));
    QApplication::addLibraryPath(dir.absolutePath());

    QApplication a(argc, argv);

...

And then put qwindows.dll (you don't need qminimal.dll) in a subdirectory of your EXE called platforms. (You can put it in .\plugins\platforms instead if you like, then you just need to change dir.absolutePath() to dir.absolutePath() + "/plugins" above.

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