Planned maintenance has been done but it did not solve the problem. So work will continue on this and a new time for trying updates will be announced asap.

QNetworkAccessManager throw "QWaitCondition" warning.

  • I am seeing a strange error "QWaitCondition: destroyed while thread is still running" under Windows using QNetworkAccessManager in blocking mode and quitting the event loop once the QNetworkReply emit finished(..). On seeing with process explorer, I see stack trace of two threads locked in _endthreadex call.

    QtCore4.dll!QEventDispatcherWin32::default constructor closure'+0x9f8
     // The QCoreApplication below is created once for the entire
     // lifetime of the app
     int qargc = 1;
     char* qargv[] = ;
     QCoreApplication ourQapp = new QCoreApplication(qargc, qargv);
     // Entry to function
     <...function ...>
     auto mgr = std::make_shared<QNetworkAccessManager>();
     QObject::connect(mgr.get(), SIGNAL(finished(QNetworkReply*)), ourQapp,    
     QNetworkRequest req(url);
     std::shared_ptr<QNetworkReply> response;
     response = std::shared_ptr<QNetworkReply>(mgr.get()->get(req));
     QNetworkReply::NetworkError status = response->error();
     if(status == QNetworkReply::NoError) {
         // do something
     } else {
         // do something
     <....return from function....>`

    Once we return from the function, I see two threads hanging around and as a result, when the application exit, I see the above warning.

    So my question is -

    1. Why are those two threads left behind even when QNetworkAccessManager emit finished?
    2. If we have to wait for threads to cleanup and have the event loop running, whats the best way to do it and return from function? Please note, I need this as a blocking call for now and doesn't need it to operate in event loop async fashion.
    3. Why is this warning seen only under Windows? Linux and Mac seem to go fine.

    The qt i am using is 4.8.

    BTW, I should also mention that QNetworkReply show the status as finished if I check in the finished slot.


  • I found this link discussing about the trace seen in Windows Not sure if this is still related to mine.

Log in to reply