PDA

View Full Version : plugin in a library



alisami
3rd October 2008, 17:48
hi,

i have been trying to import plugins to a library and link that library to another application.

the library pro file is as the following:


TEMPLATE = lib
HEADERS += testFile.h
SOURCE += testFile.cpp
CONFIG += debug static
RESOURCES += testFile.qrc # the images are stored as resources
QTPLUGIN += qjpeg


I use the Q_IMPORT_PLUGIN(qjpeg) in the library source file.

the content of the application pro file is as follows:


TEMPLATE = app
SOURCES += main.cpp
CONFIG += debug qt x11
LIBS += libTestFile.a # the library mentioned above


the code block is as follows:


int main(int argc, char* argv[])
{
QApplication app(argc, argv);
testFile file1; // constructs a toolbar having an icon (a jpeg image is used as icon)
file1.show(); // shows the toolbar
return app.exec();
}


without using the libraries and embedding the library code into the application code, the jpeg file is displayed correctly.

when using libraries, the jpeg plugin's static library is not linked to my library and when I compile the application, I get an error message regarding the Q_IMPORT_PLUGIN (undefined reference to qt_plugin_instance_qjpeg()). when I add

QTPLUGIN += jpeg
to the pro file of the application, the application is built but the image is not visible on the toolbar.

how can I embed the images to the library and use it in the application ?

alisami
3rd October 2008, 18:03
I have found the reason why the image is not displayed.

since the resource is linked to a static library, it is necessary to call

Q_INIT_RESOURCE(resourceName)

in the application in order to use the resources properly.

alisami
3rd October 2008, 18:21
is it possible to link the jpeg library to the custom created library or is it a must to link it to the main application ?