PDA

View Full Version : Problems declaring global QIcons



SkripT
7th March 2006, 12:36
Hi all, my application crashes when I make the following declarations of icons in the global space:


static const QIcon IconeInicialFotoPetita("../icone.bmp");
static const QIcon IconeLlibreObert("../llibreobert.png");
static const QIcon IconeLlibreTancat("../llibretancat.png");
static const QIcon IconeCarpetaOberta("../carpetaoberta.png");
static const QIcon IconeCarpetaTancada("../carpetatancada.png");

But it doesn't crash if I just declare them as null icons:


static const QIcon IconeInicialFotoPetita;
static const QIcon IconeLlibreObert;
static const QIcon IconeLlibreTancat;
static const QIcon IconeCarpetaOberta;
static const QIcon IconeCarpetaTancada;

Anybody could explain me why?

Thanks.

wysota
7th March 2006, 14:47
Maybe they need a QApplication object? What does the backtrace tell you?

SkripT
7th March 2006, 15:27
What does the backtrace tell you?
The strange is that when the application crashes, it doesn't give any error message, simply it closes doing nothing. When I run it with gdb debugger it only says that the appplication have exited with value 1. Strange :confused:

wysota
7th March 2006, 15:33
So does it crash or exit?

SkripT
7th March 2006, 17:50
It exits but it's really a crash

Chicken Blood Machine
7th March 2006, 18:08
If QIcon is anything like QPixmap, it requires the use of resources from the window system. In Qt apps, you cannot use any window-system resources until you have created a Application object. Static objects are created initially at program startup before the main() funciton is even entered. That is why static Qt objects are (usually) a bad idea. Stick with your null QIcons and initialize them in an init() method that you call some time shortly after startup.