Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded JPG resources not loading in Qt application

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
like image 312
dwj Avatar asked Feb 10 '10 23:02

dwj


1 Answers

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
like image 154
Eugene Avatar answered Sep 30 '22 08:09

Eugene