PDA

View Full Version : static compiled app, does not load image at runtime



babu198649
6th March 2008, 10:53
hi
i have compiled an application statically and it has to set its background with image which is present in the file system.

this is done like this


QPalette palette;
QPixmap pixmap = QPixmap("./icon/slide1.jpg");
palette.setBrush((this)->backgroundRole(), QBrush(pixmap));
(this)->setPalette(palette);

but it does not work if the program is compiled statically.

but the same program compiled dynamically (using dynamic libraries) works.

i am sure that there is no problem with path in which images are present.

do compiling statically requires any modification.

jpn
6th March 2008, 10:58
See Q_IMPORT_PLUGIN() (http://doc.trolltech.com/4.3/qtplugin.html#Q_IMPORT_PLUGIN).

babu198649
6th March 2008, 11:28
thanks jpn
i have read in other threads that creating objects in stack(like QWidget w) causes crash. but some of the classes such as QPixmap ,QPalette ,et.c , even if they are created on the stack does not crash ,why.

jpn
6th March 2008, 11:55
i have read in other threads that creating objects in stack(like QWidget w) causes crash. but some of the classes such as QPixmap ,QPalette ,et.c , even if they are created on the stack does not crash ,why.
It's not that straight-forward at all. It's perfectly valid to allocate for example the main window in main() and modal dialogs on the stack. Why? Both are QWidgets.

QObjects organize themselves in object trees (http://doc.trolltech.com/4.3/objecttrees.html). A parent takes ownership of its children and automatically deletes them when the parent is deleted. This would cause problems if children were allocated on the stack because they would (depending on the allocation order) end up being deleted twice; 1) by their parent and 2) by normal C++ rules when going out of scope. However, neither QPixmap, QPalette nor other implicitly shared classes (http://doc.trolltech.com/4.3/shared.html) are QObjects.