Recources in static lib problem
-
I've got an application. It uses class from static lib. In that class was reiplemented painEvent and it use some images which is in the resources of static lib. When I use class in apllication I have no image on screen and got the message "Image is a null image". What I'm doing wrong ?
-
The resources of a library cannot be loaded automatically. Load the resources using Q_INIT_RESOURCE.
-
Here is some code in class of static lib:
@ pressed.insert("ledsOff", QImage("qrc:/buttonImage/Resources/ButtonPressed.png"));
pressed.insert("redLed", QImage("qrc:/buttonImage/Resources/ButtonPressed_redLed.png"));
pressed.insert("greenLed", QImage("qrc:/buttonImage/Resources/ButtonPressed_greenLed.png"));
pressed.insert("ledsOn", QImage("qrc:/buttonImage/Resources/ButtonPressed_greenRedLed.png"));@And in main file of application:
@Q_INIT_RESOURCE(sxConsoleButtons);
QApplication a(argc, argv);@I use this class in designer when promote one of the PushButtons to my class.
-
I believe you cannot create resources before the QApplication object in main() has been created. Try switching those two lines in your main.
-
Have you verified that you can get the resource with that name within the static library? The "qrc:/" looks strange to me.
-
I change it to this: @pressed.insert("ledsOff", QImage(":/buttonImage/Resources/ButtonPressed.png"));
pressed.insert("redLed", QImage(":/buttonImage/Resources/ButtonPressed_redLed.png"));
pressed.insert("greenLed", QImage(":/buttonImage/Resources/ButtonPressed_greenLed.png"));
pressed.insert("ledsOn", QImage(":/buttonImage/Resources/ButtonPressed_greenRedLed.png"));unpressed.insert("ledsOff", QImage(":/buttonImage/Resources/ButtonUnpressed.png"));
unpressed.insert("redLed", QImage(":/buttonImage/Resources/ButtonUnpressed_redLed.png"));
unpressed.insert("greenLed",QImage(":/buttonImage/Resources/ButtonUnpressed_greenLed.png"));
unpressed.insert("ledsOn", QImage(":/buttonImage/Resources/ButtonUnpressed_greenRedLed.png"));@ but still can't get images. But if I use it without static lib it works fine. Maybe I need to do something else ? Some project settings in Visual Studio or any other ideas ? -
sxConsoleButtons is exactly the name of your qrc file in the static lib?
Beyond that, I'm afraid I'm stumped. I have project both with MinGW and Visual Studio that use static libs and resources, and it works.