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.

    ntdll.dll!ZwWaitForMultipleObjects+0xa
    KERNELBASE.dll!GetCurrentProcess+0x40
    kernel32.dll!WaitForMultipleObjectsEx+0xb3
    USER32.dll!GetScrollBarInfo+0x1dd
    USER32.dll!MsgWaitForMultipleObjectsEx+0x2e
    QtCore4.dll!QEventDispatcherWin32::processEvents+0x5d8
    QtCore4.dll!QEventLoop::exec+0x21f
    QtCore4.dll!QThread::exec+0xf6
    QtCore4.dll!QEventDispatcherWin32::default constructor closure'+0x9f8
    MSVCR120.dll!beginthreadex+0x107
    MSVCR120.dll!endthreadex+0x192
    kernel32.dll!BaseThreadInitThunk+0xd
    ntdll.dll!RtlUserThreadStart+0x21
    
    `
     // 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,    
         SLOT(quit()));
     QNetworkRequest req(url);
     std::shared_ptr<QNetworkReply> response;
     response = std::shared_ptr<QNetworkReply>(mgr.get()->get(req));
     ourQapp->exec();
    
     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.

    -Kartlee



  • I found this link discussing about the trace seen in Windows https://bugreports.qt.io/browse/QTBUG-7691 Not sure if this is still related to mine.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.