Hi I am developing a Qt application that uses a plugin (dynamic library) and I was wondering if there was a way I could build the application and library in one file (maybe using the QResource feature?)
Qt supports linking plugins statically to your application. See the documentation.
You use the Q_IMPORT_PLUGIN()
macro in your code like so:
#include <QApplication>
#include <QtPlugin>
Q_IMPORT_PLUGIN(qjpeg)
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
...
return app.exec();
}
You also need to list the plugins in QTPLUGIN in your .pro file:
QTPLUGIN += qjpeg
You may also need to build a static version of Qt yourself - not sure if the prebuilt versions contain static libraries (I don't use the prebuilt code).
You want an application like "DLL to Lib" that will convert your DLL file to a static library. Then you'd link with the .lib file instead of the DLL and you're all set. You can download a trial of one product here:
When you do this, make sure not to violate the license of the library. If the library isn't available as a static library, it might be under the LGPL (or even GPL). Linking statically in either case would violate the license unless you are releasing your software also under the GPL.