[Interest] QNetworkAccessManager in a command line, non-eventloop application
Scott Aron Bloom
scott.bloom at onshorecs.com
Fri Jan 18 01:59:13 CET 2013
I have a command line application, with no event loop.
I also have a function where I need the tool to send a HTML request out, and not care about the result..
There is 1 and only 1 QNAM.
I know what the issue is, there is NO event loop, what I would like to do is have a QThread (or a concurrent class equivalent) for the requests. I just push a request into the thread, which has its own event loop.
Then I want to simply wait at the end of the command line tool, for the Thread to finish..
I have tried all sorts of crap (and yes I admit its crap) code for the QThread based approach.. Any help would be appreciated.
Scott
std::list< QNetworkReply * > replies;
void sendRequest()
{
QNetworkReply * reply = nam.get( QNetworkRequest( QUrl( "http://www.google.com" ) ) );
replies.push_back( reply );
}
bool isRequstPending()
{
Bool hasPending = false;
For( std::list<QNetworkReply * >::iterator ii = replies.begin(); !hasPending && ii != replies.end(); ++ii )
{
hasPending = (*ii)->isFinished();
}
return hasPending;
}
int main( int argc, char ** argv )
{
QCoreApplication appl( argc, argv );
sendRequest();
sendRequest();
sendRequest();
sendRequest();
while( isRequestPending() )
{
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130118/ab1704bc/attachment.html>
More information about the Interest
mailing list