You can create the instance of the QCoreApplication
in a new thread in the library. You should check to create only one instance of it, That's because each Qt application should contain only one QCoreApplication
:
class Q_DECL_EXPORT SharedLibrary :public QObject {Q_OBJECTpublic: SharedLibrary();private slots: void onStarted();private: static int argc = 1; static char * argv[] = {"SharedLibrary", NULL}; static QCoreApplication * app = NULL; static QThread * thread = NULL;};SharedLibrary::SharedLibrary(){ if (thread == NULL) { thread = new QThread(); connect(thread, SIGNAL(started()), this, SLOT(onStarted()), Qt::DirectConnection); thread->start(); }}SharedLibrary::onStarted(){ if (QCoreApplication::instance() == NULL) { app = new QCoreApplication(argc, argv); app->exec(); }}
This way you can use your Qt shared library in even non Qt applications.