QTest and QEventLoop inside a library
Hi all,
inside a library I have code like:
Code:
QNetworkReply* AIDAW::getRequest(const QString& url){
QNetworkRequest request(url);
QNetworkReply *reply = this->network_manager->get(request);
QObject::connect(reply,
SIGNAL(finished
()),
&loop,
SLOT(quit
()));
QObject::connect(&timer,
SIGNAL(timeout
()),
&loop,
SLOT(quit
()));
timer.start(TIMEOUT);
loop.exec();
if(timer.isActive() == false){
//manage the timeout
}
return reply;
}
If I try to write a QTest Project using this library I get this error:
Code:
********* Start testing of MyProject *********
Config: Using QTest library 4.7.0, Qt 4.7.0
PASS : AIDATest::initTestCase()
QObject::connect: Cannot
connect (null)::aboutToQuit() to QNativeWifiEngine
::clo seHandle()
the main of the test project is managed by QTEST_MAIN(MyTestClass) macro
Re: QTest and QEventLoop inside a library
It is unwise to start an event loop within an event loop. The issue you run into right now could be one you run into when running a program using the library. In this case you should probably start a thread (with an event loop then) and wait until the thread has finished doing it's job. Alternatively you could try a different approach, but that would require more knowledge of the nature of your system. See also http://labs.qt.nokia.com/2010/02/23/unpredictable-exec/.