PDA

View Full Version : Relase build has no images (PNG) yet Debug does



mclark
18th May 2010, 22:29
Windows XP SP3
Visual Studio 2005
Qt 4.6.2 (same problem with 4.5.2)

I build my program in both Debug and Release modes. In the debugger I can see all my icons but running the Release version - no icons (png, jpg, svg). I'm using the Qt resource compiler for my images (this should embed the images into the executable corrrect?).

I thought maybe I needed the '/imageformats' directory but this made no difference (even after adding 'QCoreApplication::addLibraryPath("Z:/MyAppDir/imageformats");' to my QMainWindow constructor).

I add icons using 'const QString' or explicit strings like:

setWindowIcon( QIcon( ":/images/monkey_on_128x128.png" ) );
In the resouces.qrc file this image is listed as:

<file>../images/monkey_on_128x128.png</file>
I've tried running the executable from the Release directory and the project root directory but, alas, no images appear. I have also created the icon and dump the result (null or not) to my log file. The images never report that they are null.

I went through the forum but saw nothing about this particular situation. Does anyone have any suggestions for me to try?

Lykurg
18th May 2010, 22:44
Try to set an alias for your file. I think otherwise you have to use exactly the same name as the value of file. In your case with "../".
Did you use the sdk or have you build Qt yourself?

mclark
18th May 2010, 22:48
Did you use the sdk or have you build Qt yourself?I'm using a commercial build of Qt 4.6.2

I'll try the alias test but wouldn't not using an alias be a problem for the Debug build too?

Lykurg
18th May 2010, 22:58
Ok, sorry, I hadn't noticed, that in debug mode it works, only in release mode it doesn't.

Are you sure, you have the needed plugins build in release mode? In debug you obviously have, if you see the images...


EDIT: Because if it works on debug and not on release mode, the only reason could be missing (release mode) libraries.

mclark
18th May 2010, 23:13
Try to set an alias for your file.I went from:
<file>../images/monkey_on_128x128.png</file>
to
<file alias="monkey_on_128x12.png">../images/monkey_on_128x128.png</file>
and when creating the QIcon:
QIcon(":/images/monkey_on_128x12.png")
to
QIcon("monkey_on_128x12.png")
with no change in the output in the Release build (still missing). On the other hand, this image is now missing from the Debug build!


Are you sure, you have the needed plugins build in release mode?
I believe that the png files should be handled internally by Qt for both builds. The jpg and svg may need the plugins. In my 'Z:\MyAppDir\imageformats' directory I have: qjpeg4.dll and qsvg4.dll, which are part of the Qt commercial release build (as opposed to qjpegd4.dll).

ChrisW67
19th May 2010, 01:27
and when creating the QIcon:
QIcon(":/images/monkey_on_128x12.png") to
QIcon("monkey_on_128x12.png") with no change in the output in the Release build (still missing). On the other hand, this image is now missing from the Debug build!
Are you sure the new line shouldn't be:
QIcon(":/monkey_on_128x12.png") assuming that the aliased file is still listed inside a:
<qresource prefix="/"> ... </qresource> block?

mclark
19th May 2010, 17:46
ChrisW67, you are correct. My use of the resource string in QIcon() was incorrect.

I changed to QIcon( ":/monkey_on_128x128.png" ).

Again, in Release AND Debug mode, no images.

Although, on the plus side; I added <file alias="sensor.svg">../images/sensor.svg</file> to the resource file and when calling QGraphicsSvgItem(":/sensor.svg"), the SVG shows up as expected in Debug mode.

In any case whenever I create an QIcon I check the result using icon.isNull() and dump the result to my log file. In all cases it reports the icon is NOT null.

mclark
19th May 2010, 23:09
The problem is with the way my Visual Studio project is set up. Debug and Release version of the executable are run from different directories BUT the Debug version looks for everything from the ApplicationRoot directory while the Release does not.

I fixed my problems by:

Having the Release executable placed, not in the Release subdirectory, but in the ApplicationRoot directory
I added this line to my main window constructor to alias the location of my image directory:

QDir::setSearchPaths( "icons", QStringList( QDir::currentPath() + "/images" ) );
I removed all image references from my resource (qrc) file
All images referenced internally are now accessed by:
QIcon("icons:image_file.png");
This allows my to add and use images without having to recompile (which this project must do) and makes the executable smaller.