Qt 5.0 program runs in QtCreator but not outside

2019-01-07 23:59发布

Here is the context:

  • I have developed a program with Qt under Windows 7 x64.
  • I have upgraded to Qt 5.0.1, QtCreator 2.6.1, Compiler VS2010.

Now the status:

  • My program runs fine in QtCreator but, when I tried it outside, I received several errors.
  • I checked this topic which gave me some answers: qtcreator - exe does work fine inside qtcreator but doesn't outside
  • I thus added Qt dlls and it helped, no more Missing Libraries messages.
  • Still, it would not run outside QtCreator (no more error message, I just doesn't run) so I added the platforms directory with both qminimal and qwindows dlls, it didn't help.
  • I also downloaded and added libEGL.dll as sugested, with no result.

I'm stuck and could really a little help.

3条回答
贼婆χ
2楼-- · 2019-01-08 00:49

This is a dependency problem that your program can not load its dependencies, copy dependency files (DLL files) to application directory is a temporary way, this is very risky way that your application may faced with problems in target machine, if target machine does not have correct version of Microsoft Runtime Library installed on them, your application can not run correctly, you can find which dependenices (DLL files) your application needs them with Dependency Walker.

There are two ways to solve this:

First one is to use Microsoft Visual C++ 2010 Runtime components in your installshield (or another versions depends on which version of Runtime library you compiled with it), that user could install it silently, or install with its executable binary without use installshield, and later copy DLL files to application directory and distribute it.

Second is use static compilation method to avoid such problems like that, but for static compile of your application you need a Commercial License if you want to distribute it on target machines.

For Deploy Your Application on target machines:

1) Put Microsoft Visual C++ 2010 Runtime Library in your application folder, so user will install it on their machine.

2) Copy application required dependencies (DLL files) from Qt's bin folder in your application folder (bin folder path:C:\Qt\Qt5.0.2\5.0.2\msvc2010\bin).

3) Copy imageformats folder from your Qt's plugins folder in your application folder (if you use any image resource file in your application).

4) Copy platforms folder from your Qt's plugins folder in your application folder.

Qt's plugins folder path: C:\Qt\Qt5.0.2\5.0.2\msvc2010\plugins\

查看更多
ら.Afraid
3楼-- · 2019-01-08 00:57

The Qt-project site is full of such topics. Tracking dependencies will only inform of compile time dependencies. There are also DLLs that are loaded dynamically you wont' get any error, warning or whatsoever. If you use a stock build the DLLs (excluding Qt5*.dll) you'd need are:

  • D3DCompiler_46.dll (sometimes D3DCompiler_43.dll)
  • libEGL.dll
  • libGLESv2.dll
  • icudt49.dll
  • icuin49.dll
  • icuuc49.dll
  • platforms\qwindows.dll (or whatever your os is)

Plus compiler runtime dlls depending on what build you are using.

You can cut on dependencies significantly if you build with desktop OpenGL support instead of ANGLE and without the webkit. Then you only need the platform plugin and the Qt modules you are using.

查看更多
▲ chillily
4楼-- · 2019-01-08 01:01

just add the file qt.conf to your app directory with the following content

[Paths]

Libraries=./platforms

then copy, to same app directory, the sub-directory "platforms" that you can find in: C:\Qt\Qt5.1.1\Tools\QtCreator\bin

That's all.

This works because qtcore.dll is compiled with the internal paths of your qt installation. (I don't know why!). Since t.conf is always read by qtcore when the app starts, the librarys in "platforms" will be included and the app will work for any host.

Warning: the qtcore and platforms sub directory have to come from the same qt installation.

查看更多
登录 后发表回答