desktop app crashed when multiple event loops are used in code
-
wrote on 5 Apr 2017, 15:16 last edited by
I am trying to write some data to an url using get request from QNetworkAccessManager class. I am creating an event loop in it. There is another event loop running in the main thread which is the main event loop for the application. The application is getting crashed when it reaches eventLoop.exec(); line in the code below. Any idea why is it happening??
bool Write(QNetworkRequest request) const
{
QEventLoop eventLoop;
connect(networkAccessManager.get(), &QNetworkAccessManager::finished, &eventLoop, &QEventLoop::quit);
int count = 0;
while (count < retryCount)
{
QNetworkReply* reply = networkAccessManager->get(request);
eventLoop.exec();
if (reply != NULL && reply->error() == 0)
return true;
count++;
}
return false;
}**networkAccessManager is the QNetworkAccessManager object.
-
I am trying to write some data to an url using get request from QNetworkAccessManager class. I am creating an event loop in it. There is another event loop running in the main thread which is the main event loop for the application. The application is getting crashed when it reaches eventLoop.exec(); line in the code below. Any idea why is it happening??
bool Write(QNetworkRequest request) const
{
QEventLoop eventLoop;
connect(networkAccessManager.get(), &QNetworkAccessManager::finished, &eventLoop, &QEventLoop::quit);
int count = 0;
while (count < retryCount)
{
QNetworkReply* reply = networkAccessManager->get(request);
eventLoop.exec();
if (reply != NULL && reply->error() == 0)
return true;
count++;
}
return false;
}**networkAccessManager is the QNetworkAccessManager object.
wrote on 5 Apr 2017, 15:42 last edited byThere is no need to have duplicated threads in this forum.
1/2