Embedded JPG resources not loading in Qt application

∥☆過路亽.° 提交于 2019-12-17 16:22:59

问题


I have a Qt application that has some embedded JPG files that I want to display. When I compile and run both the debug and release versions on my machine, everything works perfectly. When I copy the application to a thumb drive and run it from there on my machine, it works fine. On the thumb drive and another developer's machine: OK. On the thumb drive on a third, non-developer's machine: no images!

proj.pri
RESOURCES += ./proj.qrc

proj.qrc:
<RCC>
<qresource prefix="/myApp">
    <file>Gui/Resources/logo.jpg</file>
    <file>Gui/Resources/another_image.jpg</file>
</qresource>
</RCC>

main.cpp:
{
    ...
    QImage *logo  = new QImage( ":/myApp/Gui/Resources/logo.jpg" );
    QImage *image = new QImage( ":/myApp/Gui/Resources/another_image.jpg" );

    myClass *d1 = new myClass( "Some Text", 48, 30, logo );
    myClass *d2 = new myClass( "Some More Text", 48, 30, another_image );
    ...
}

I have confirmed that the images are being added to the executable by commenting out the RESOURCES line in the .pri file. The size of the binary drops by the size of the images plus a bit; when I run the application, the images do not appear. I un-comment the RESOURCES line and everything works as described above.

What am I missing here? A DLL on the non-developer's machine? A

Environment:

  • Win XP
  • Qt 4.6.1
  • Visual Studio 2008
  • Qt Creator 1.3.1

回答1:


It needs jpeg plugin to load images. If you have Qt installed they would be in %QTDIR%\plugins\imageformats.

Copy qjpeg4.dll into plugin folder on your thumb drive.

root/app.exe
root/qt.conf
root/plugins/imageformats/qjpeg4.dll

In qt.conf file set path to your plugins dir:

[Paths]
plugins=./plugins



回答2:


While the most accurate answer is given already, rather than having to deploy more dlls and a folder structure, I find it much easier to just convert the images to png...no image format dlls etc. required if you use pngs.



来源:https://stackoverflow.com/questions/2241141/embedded-jpg-resources-not-loading-in-qt-application

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