使用 Qt 显示 JPG 图像不适用于发布可执行文件

2021-12-09 00:00:00 jpeg qt executable release c++

我在用 qt 显示 jpg 图像时遇到了一个烦人的问题.我在 Windows 7 中使用 Visual Studio 2008 进行开发,并使用 Qt 4.8.2 版.我现在将通过 Qt 提供的collidingmice"示例来描述我的问题(../examples/graphicsview/collidingmice).

i have a annoying issue with showing jpg images with qt. I devlope with Visual Studio 2008 in Windows 7 and using the Qt version 4.8.2. I will now describe my problem by means of the "collidingmice" example deliverd with Qt (../examples/graphicsview/collidingmice).

我可以通过 Visual Studio IDE 或通过 Visual Studio 命令提示符构建此示例.在此示例中,jpg 用作背景,并在我执行调试可执行文件时正确显示.但在发布版本中,此背景 jpg 未显示.

I can build this example via Visual Studio IDE or with via the Visual Studio command prompt. In this example a jpg is used as background and is correctly shown when I execute the debug executable. But in release build this background jpg is not shown.

我已经意识到,Qt 使用插件来加载/显示不同的图像.因此我将Qt的插件文件夹的内容复制到应用程序目录中(collidingmice.exe所在的位置).不幸的是,这并不能解决问题.

I already realized, that Qt uses plugins for loading/showing different images. Therefore I copied the contents of the plugin folder of Qt into the application directory (where collidingmice.exe is). Unfortunatly, this does not solve the problem.

因此,我认为 Qt 构建和 jpeg 库一定有问题.因此,我通过在 Visual Studio 命令提示符下执行以下命令重新配置了 Qt:

Hence, I thought there must be something wrong with the Qt build and the jpeg library. Therefore, I reconfigured Qt by executing the following commands in the Visual Studio command prompt:

nmake distclean
configure -debug-and-release -opensource -platform win32-msvc2008 -qt-libjpeg -no-webkit
nmake

之后对示例进行了重建,但再次未显示 jpg 图像.我不确定问题是什么,因为它在调试版本和发布版本中都有效,我想我只需要提供所需的插件 DLL.但显然我是不对的.

After that did a rebuild of the example, but again the jpg image is not shown. I am not sure what the problem is since it works in debug build and in release I think I only have to deliver the needed plugin DLLs. But obviously I am not right.

我希望任何人都可以帮助我,或者可以给我一些可能出现问题的提示.谢谢!

I hope anyone can help me or can give me some hints where the problem might be. Thanks!

推荐答案

所以我把Qt的plugin文件夹的内容复制到了应用程序目录(collidingmice.exe 所在的目录).

Therefore I copied the contents of the plugin folder of Qt into the application directory (where collidingmice.exe is).

您需要将插件放入imageformats"子目录,例如喜欢

You need to put the plugins into an "imageformats" subdirectory, e.g. like

bin
 ├── collidingmice.exe
 └── imageformats
       ├── qjpeg4.dll
       ├ ...

另见 http://www.qtcentre.org/threads/46927-图像格式目录的位置

原来OP已经相应地设置了目录结构.根本原因是加载了错误的 QtGui4.dll.这可以通过将 DLL 直接复制到应用程序目录中或通过更改 PATH 环境变量中的路径顺序来解决,以便您的 Qt bin 目录位于包含 QtGui4.dll 的所有其他路径的前面.

It turned out that the OP had already set up the directory structure accordingly. The root cause was that a wrong QtGui4.dll has been loaded. This can be fixed "by copying the DLL directly into the application directory or by changing the order of the paths in the PATH environment variable so that your Qt bin directory is placed in front of all other paths containing a QtGui4.dll."

无论如何,进程监视器是一个很好的工具追踪此类问题.

In any case, the Process Monitor is a good tool to track down such issues.

相关文章