QEventLoop: Cannot be used without QApplication Qt static
-
Hi all,
I am building a SDK using Qt 5.7.0 static when I test it with an application I get the error in the title.
The SDK depends on multiple libraries including SingalR client for c++ .
I built the SDK and tester with Qt 5.7.0 dynamic and it ran without any error , it only appears when I build the SDK and depends static.Can anybody point me to what may cause this ?
Thanks in advance. -
Which platform ? Can you show us where are you creating the Application objects ?Typcially your main.cpp code. It helps to help you.
-
@dheerendra
The system is Ubuntu . I can't show all the code in my main but here is how it looks like :loggingFunction(); QCoreApplication a(argc, argv); ChooseSDKFunction(); ConfigurationFunction(); RunSDKFunction(); //The error appears inside this function // // QFuture<void> task = QtConcurrent::run([&] { // ProgramExecutable(); // }); std::future<void> future = std::async(std::launch::async,[&]{ ProgramExecutable(); }); int result = a.exec(); return result;
-
loggingFunction() doesn't have an event loop it is a simple two lines code to initialize the logger of the program.
I put QCoreApplication first and it doesn't change the output of the program.
-
@VRonin
Yes I have a single global variable but used only in main function and ProgramExecutable() function and what i posted is the main function of the tester.
I followed the source of the error inside SignalR client code to a call to get function for a webpage. -
What puzzles me what the difference between the static build and dynamic that could cause this ?
-
@VRonin
Yes I have a single global variable but used only in main function and ProgramExecutable() function and what i posted is the main function of the tester.
I followed the source of the error inside SignalR client code to a call to get function for a webpage.@Mohammedbie can you show the global variable? which type is it?
-
There is not difference between the static and dynamic build. It could be the way you have written something. It could be the way you have defined the global variables somewhere. Some where you are creating some Qt objects globally without creating the QApplication object.
-
@Mohammedbie can you show the global variable? which type is it?
I'm almost ready to bet that a
QThread
was created at global scope ... [1] -
@aha_1980
it is a custom made class which have all the SDK operation I can't show it it all but here how it looks like :class Program : public QObject { Q_OBJECT public: Program(QCoreApplication &app , int instance); void Operation1(); void Operation2(); void Operation3(); void Operation4(); void Operation5(); void Operation6(); CustomClass2* Operation7(); void Operation8(); CustomClass2* CustomInstance; CustomClass3* CustomInstance2; CustomClass4* CustomInstance3; CustomClass5* CustomInstance4; const char *pin = "1234"; static QHash<QString, QString> prop; private: QVector<QUuid> *OpenSessions = new QVector<QUuid>(); CustomClass4*a; QSslCertificate * cert; QSslKey * key; QList<QSslCertificate> * importedCerts; public slots: void Slot1(arg args); void Slot2(arg *args); void Slot3(arg *args); void Slot4(arg *args); void Slot5(arg * args); void Slot6(arg * args); QUuid Slot7(); int Slot8(); void Slot9(); };
-
It could be code something like this. Since you are not showing the code we can only guess & try to help you. E.g See the following code. Thread object is created in global scope. When you try start the thread, it will starts its event loop. Simillary I'm just trying to create the event loop object. When you QEventLoop object is created, QApp object should exist.
QThread th; int main(int argc, char *argv[]) { //th.start(); QEventLoop loop; QApplication a(argc, argv); Widget w; w.show(); return a.exec(); } So you need to start looking at your code for such instances.
-
The same SDK ran on windows with no problem with Qt5.12.0 static.
-
You never know if you have ifdef for windows. You need to identify the specific statement where this issue comes.
-
Yes on the windows we are using the native functions of the windows but it is used in Networking and logging only and the difference only in the includes and functions name.
-
Since you say it is coming from RunSDK method, can you tell us which Qt classes you use inside this class. Where are you creating them ? Also you error is only following statement. Is that correct ?
"QEventLoop: Cannot be used without QApplication"
There is no "Qt Static" appended at the end. -
There are many levels in this function as I call other functions in it, the first level of the function uses :
QString qDebug() QFile QSslCertificate QSslKey QList QByteArray QUuid QLoggingCategory QHashand yes the message is without "Qt Static" I added it as it only happens with Qt static.
-
I sill can't understand what cause this in Qt static and not in Qt dynamic of the same version as the code in the two cases the same .
-
I'm going back to basics. Can you create the simple Qt Project with your static Qt build & check if this works ? If this is not working we can see why it is so. Please note. By any chance
- By any chance QCoreApplication object what you are creating, is it getting destroyed ?
- Can you try handling destroyed.. signal like the follows in main.cpp
QObject::connect(a,&QApplication::destroyed,[](){ qDebug() << Q_FUNC_INFO << " I am dying " << endl;} );
- This error comes from only one source in Qt & it is QEventLoop. Issue can happen only if the QCoreApp instance is not created, created but destroyed.
- We have to just focus on the commenting out some code in RunSDK method & figure out.
- Since we don't have code, I'm proposing different possibilities to check the error.