PDA

View Full Version : Exe not displaying images when compiled statically



premroxx
29th August 2011, 01:38
Hello,
I have built a gui, using some jpegs for background images(set using pixmap property in Qt creator). It run fine in the Qt creator. But, when i tried to execute the exe(i have copied all the missing dll's it asked for), it seems to work fine but does not display the images. I looked through lots of similar posts & here is what i have tried so far.

a)
I have configured it statically
configure -static -qt-libjpeg
nmake

b)
I have tried to add images using resource editor, instead of loading them directly from a folder.
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>images/begin1.jpg</file>
<file>images/emerg.jpg</file>
</qresource>
</RCC>
i have placed my jpegs in the 'images' folder(which i copied into the folder where my exe & qrc is located). I have also created an 'imageformat' folder which has the 'qjpeg4.dll' file

c) i have edited my pro file

CONFIG += static
RESOURCES = interface.qrc

& my mainwindow.cpp -> Q_INIT_RESOURCE(interface);

d)
I took a detour & tried using Qt plugins, but i had a link error. So i gave up on that.


As, far as using the jpegs in my program, here is an example:

this->ui->label_begin->show(); (label_begin's pixmap property loads begin1.jpg)


Can you please point out the error i'm making? Thanks in Advance. If i hadn't given you enough information, do let me know as of what else you might need.


Prem.

ChrisW67
29th August 2011, 02:06
You have to ship the JPEG image format plugin, and probably others, with your application. If you are dynamically linking then they can simply be dropped in the correct place near your executable. If you are using a static Qt then the plugins must be built-in.

premroxx
29th August 2011, 02:37
Thanks for the quick reply. I tried to do it dynamically. when i tried to add the plugin, I get link errors

in main.cpp
#include <QtPlugin>
Q_IMPORT_PLUGIN(qjpeg)

in the .pro file
QTPLUGIN += qjpeg
(for some reason the word 'QTPLUGIN' doesn't appear in purple colour)

i get the link error:
main.obj:-1: error: LNK2019: unresolved external symbol "class QObject * __cdecl qt_plugin_instance_qjpeg(void)" (?qt_plugin_instance_qjpeg@@YAPAVQObject@@XZ) referenced in function "public: __thiscall StaticqjpegPluginInstance::StaticqjpegPluginInstan ce(void)" (??0StaticqjpegPluginInstance@@QAE@XZ)

What more should i add?

Thank You.

wysota
29th August 2011, 06:59
I tried to do it dynamically.
No, you didn't. The code posted suggests you are trying to use static plugins. The question is whether you have static plugins built in the first place.

Wyrlin
29th August 2011, 13:02
When building statically you may need to explicit load the .qrc resource file using the Q_INIT_RESOURCE (http://doc.qt.nokia.com/latest/qdir.html#Q_INIT_RESOURCE) macro:


Q_INIT_RESOURCE(Backgrounds);

This should be done in the main.cpp file before the QApplication is constructed, if I'm not mistaken.

By the way: This was my first post, so I really hope it helps :)

premroxx
31st August 2011, 01:30
question is whether you have static plugins built in the first place

This is what i have done so far.

.pro
CONFIG += static
QTPLUGIN += qjpeg

main.cpp
#include <QtPlugin>
Q_IMPORT_PLUGIN(qjpeg)

I am getting an link(LINK2019) error. I also notice that the word 'QTPLUGIN' isn't showing up in a violet color like the other QT commands do? I have a imageformats folder(next to my .exe) with libqjpeg.a in it. What else am i doing wrong?

ChrisW67
31st August 2011, 05:43
What is the error? My crystal ball is out of action... ;)

premroxx
31st August 2011, 06:42
main.obj:-1: error: LNK2019: unresolved external symbol "class QObject * __cdecl qt_plugin_instance_qjpeg(void)" (?qt_plugin_instance_qjpeg@@YAPAVQObject@@XZ) referenced in function "public: __thiscall StaticqjpegPluginInstance::StaticqjpegPluginInstan ce(void)" (??0StaticqjpegPluginInstance@@QAE@XZ)

debug\interface.exe:-1: error: LNK1120: 1 unresolved externals

wysota
31st August 2011, 07:46
Forget the imageformats folder, it's only for dynamic plugins. The static plugins need to be available at compile time where the linker can find them.

Wyrlin
1st September 2011, 08:07
Have you built Qt statically?
You need to build your application with a static version of Qt, not just configure your project for a static build. If you have built both Qt and your application statically you should not need any Qt related dll's. In any event, when using qrc files you do not need to deploy the image files after compilation, they will be built inn to your executable.

From the error message it looks like the linker can't find the static version of the qjpeg library, indicating either a faulty path or that you don't have the qjpeg static library. Static files will most likely be .a files if you are using the MinGW compiler, and .lib if you are using msvc.

If all you want is for your images to show in the application, perhaps the dynamic approach is the better one, using qrc resource files. If you need to deploy your application as a part of your job, then static build may be the way to go, however you do need a commercial Qt license to deploy static Qt applications.