You can create an instance of QCoreApplication in a new thread in the library. You must check to create only one instance, because each Qt application must contain only one QCoreApplication :
class Q_DECL_EXPORT SharedLibrary :public QObject { Q_OBJECT public: 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 shared Qt library even in applications other than Qt.
source share