問題描述
我在用 qt 顯示 jpg 圖像時(shí)遇到了一個(gè)煩人的問題.我在 Windows 7 中使用 Visual Studio 2008 進(jìn)行開發(fā),并使用 Qt 4.8.2 版.我現(xiàn)在將通過 Qt 提供的collidingmice"示例來(lái)描述我的問題(../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 命令提示符構(gòu)建此示例.在此示例中,jpg 用作背景,并在我執(zhí)行調(diào)試可執(zhí)行文件時(shí)正確顯示.但在發(fā)布版本中,此背景 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.
我已經(jīng)意識(shí)到,Qt 使用插件來(lái)加載/顯示不同的圖像.因此我將Qt的插件文件夾的內(nèi)容復(fù)制到應(yīng)用程序目錄中(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.
因此,我認(rèn)為 Qt 構(gòu)建和 jpeg 庫(kù)一定有問題.因此,我通過在 Visual Studio 命令提示符下執(zhí)行以下命令重新配置了 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
之后對(duì)示例進(jìn)行了重建,但再次未顯示 jpg 圖像.我不確定問題是什么,因?yàn)樗谡{(diào)試版本和發(fā)布版本中都有效,我想我只需要提供所需的插件 DLL.但顯然我是不對(duì)的.
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.
我希望任何人都可以幫助我,或者可以給我一些可能出現(xiàn)問題的提示.謝謝!
I hope anyone can help me or can give me some hints where the problem might be. Thanks!
推薦答案
所以我把Qt的plugin文件夾的內(nèi)容復(fù)制到了應(yīng)用程序目錄(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-圖像格式目錄的位置
原來(lái)OP已經(jīng)相應(yīng)地設(shè)置了目錄結(jié)構(gòu).根本原因是加載了錯(cuò)誤的 QtGui4.dll.這可以通過將 DLL 直接復(fù)制到應(yīng)用程序目錄中或通過更改 PATH 環(huán)境變量中的路徑順序來(lái)解決,以便您的 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."
無(wú)論如何,進(jìn)程監(jiān)視器是一個(gè)很好的工具追蹤此類問題.
In any case, the Process Monitor is a good tool to track down such issues.
這篇關(guān)于使用 Qt 顯示 JPG 圖像不適用于發(fā)布可執(zhí)行文件的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!