#include #include #include namespace myx { namespace redis { void RequestPrivate::quitEventLoop() { loop.exit( 1 ); } Request::Request( QObject* parent ) : QObject( parent ), d ( new RequestPrivate ) { connect( this, &Request::reply, this, &Request::deleteLater ); } bool Request::waitForReply( int msecs ) { QTimer timer; timer.setInterval( msecs ); timer.setSingleShot( true ); connect( &timer, &QTimer::timeout, &d->loop, &QEventLoop::quit ); connect( this, &Request::reply, d.data(), &RequestPrivate::quitEventLoop ); /* * If the timer fires, the return value will be 0. * Otherwise, quitEventLoop() will terminate the loop with 1. */ return( ( d->loop.exec( QEventLoop::ExcludeUserInputEvents ) != 0 ) ); } } // namespace redis } // namespace myx