Quantcast
Channel: Qt: Using QCoreApplication / QNetworkAccessManager with Shared Dynamic C++ Library - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Nejat for Qt: Using QCoreApplication / QNetworkAccessManager with Shared Dynamic C++ Library

$
0
0

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.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>