本文整理汇总了C++中QEventLoop::exec方法的典型用法代码示例。如果您正苦于以下问题:C++ QEventLoop::exec方法的具体用法?C++ QEventLoop::exec怎么用?C++ QEventLoop::exec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QEventLoop
的用法示例。
在下文中一共展示了QEventLoop::exec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createFolder
bool Dropbox::createFolder(QString path)
{
// do we have a token
QString token = appsettings->cvalue(context->athlete->cyclist, GC_DROPBOX_TOKEN, "").toString();
if (token == "") return false;
// lets connect and get basic info on the root directory
QString url("https://api.dropboxapi.com/1/fileops/create_folder?root=auto&path=" + path);
// request using the bearer token
QNetworkRequest request(url);
request.setRawHeader("Authorization", (QString("Bearer %1").arg(token)).toLatin1());
QNetworkReply *reply = nam->get(request);
// blocking request
QEventLoop loop;
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
// 403 EXISTS, otherwise OK
return (reply->error() == QNetworkReply::NoError);
}
示例2: connect
void
StravaDialog::requestSearchRide()
{
progressBar->setValue(0);
progressLabel->setText(tr("Searching corresponding Ride"));
QEventLoop eventLoop;
QNetworkAccessManager networkMgr;
connect(&networkMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestSearchRideFinished(QNetworkReply*)));
connect(&networkMgr, SIGNAL(finished(QNetworkReply *)), &eventLoop, SLOT(quit()));
QByteArray out;
QUrl url = QUrl(STRAVA_URL1 + "rides?athleteId="+athleteId+"&startDate="+ride->ride()->startTime().toString("yyyy-MM-dd")+"&endDate="+ride->ride()->startTime().addDays(1).toString("yyyy-MM-dd"));
QNetworkRequest request = QNetworkRequest(url);
//request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
networkMgr.get(request);
eventLoop.exec();
}
示例3: getLegendGraphic
QImage QgsAmsProvider::getLegendGraphic( double /*scale*/, bool forceRefresh, const QgsRectangle * /*visibleExtent*/ )
{
if ( mLegendFetcher->haveImage() && !forceRefresh )
{
return mLegendFetcher->getImage();
}
QEventLoop evLoop;
connect( mLegendFetcher, &QgsImageFetcher::finish, &evLoop, &QEventLoop::quit );
connect( mLegendFetcher, &QgsImageFetcher::error, &evLoop, &QEventLoop::quit );
mLegendFetcher->start();
evLoop.exec( QEventLoop::ExcludeUserInputEvents );
if ( !mLegendFetcher->errorTitle().isEmpty() )
{
mErrorTitle = mLegendFetcher->errorTitle();
mError = mLegendFetcher->errorMessage();
return QImage();
}
else
{
return mLegendFetcher->getImage();
}
}
示例4: paintSelection
void paintSelection()
{
#if 0
SoAnnotation* hudRoot = new SoAnnotation;
hudRoot->ref();
SoOrthographicCamera* hudCam = new SoOrthographicCamera();
hudCam->viewportMapping = SoCamera::LEAVE_ALONE;
// Set the position in the window.
// [0, 0] is in the center of the screen.
//
SoTranslation* hudTrans = new SoTranslation;
hudTrans->translation.setValue(-1.0f, -1.0f, 0.0f);
QImage image(100,100,QImage::Format_ARGB32_Premultiplied);
image.fill(0x00000000);
SoSFImage sfimage;
Gui::BitmapFactory().convert(image, sfimage);
SoImage* hudImage = new SoImage();
hudImage->image = sfimage;
// Assemble the parts...
//
hudRoot->addChild(hudCam);
hudRoot->addChild(hudTrans);
hudRoot->addChild(hudImage);
Gui::View3DInventorViewer* viewer = this->getViewer();
static_cast<SoGroup*>(viewer->getSceneGraph())->addChild(hudRoot);
QWidget* gl = viewer->getGLWidget();
DrawingPlane pln(hudImage->image, viewer, gl);
gl->installEventFilter(&pln);
QEventLoop loop;
QObject::connect(&pln, SIGNAL(emitSelection()), &loop, SLOT(quit()));
loop.exec();
static_cast<SoGroup*>(viewer->getSceneGraph())->removeChild(hudRoot);
#endif
}
示例5: doSyncGet
static int doSyncGet(const QString &rootUrl, QByteArray &result)
{
QNetworkRequest url;
url.setUrl(rootUrl);
QScopedPointer<QNetworkAccessManager> connection(new QNetworkAccessManager);
QScopedPointer<QNetworkReply> reply(connection->get(url));
qDebug() << "doSyncGet" << rootUrl;
QEventLoop waitLoop;
QObject::connect(reply.data(), SIGNAL(finished()), &waitLoop, SLOT(quit()));
waitLoop.exec();
int errorCode = reply->error();
if (errorCode != 0) {
qWarning() << "get" << url.url() << reply->errorString();
return errorCode;
}
result = reply->readAll();
return errorCode;
}
示例6: search
QVariant parseAPI::search(const QVariant& keyword)
{
QEventLoop eventLoop;
QObject::connect(&network, SIGNAL(finished(QNetworkReply* )), &eventLoop, SLOT(quit()));
qDebug()<<"开始循环事件";
QNetworkRequest request(QUrl(QString("http://music.163.com/api/search/get/")));
request.setRawHeader("Referer", "http://music.163.com");
request.setRawHeader("Cookie", "appver=2.0.2");
request.setRawHeader("Content-type","application/x-www-form-urlencoded");
QByteArray parameter;
parameter.append("s="+keyword.toByteArray());
parameter.append("&offset=0&limit=24&type=1");
QNetworkReply* reply=network.post(request, parameter);
eventLoop.exec();
if(reply->error() == QNetworkReply::NoError){
QByteArray json=reply->readAll();
return QVariant(json);
}
return QVariant("");
}
示例7: shutdownServer
// Shutdown the application server
bool shutdownServer(QUrl url)
{
QNetworkAccessManager manager;
QEventLoop loop;
QNetworkReply *reply;
QVariant redirectUrl;
url.setPath("/misc/shutdown");
do
{
reply = manager.get(QNetworkRequest(url));
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
url = redirectUrl.toUrl();
if (!redirectUrl.isNull())
delete reply;
} while (!redirectUrl.isNull());
if (reply->error() != QNetworkReply::NoError)
{
return false;
}
QString response = reply->readAll();
if (response != "SHUTDOWN")
{
qDebug() << "Failed to connect, server response: " << response;
return false;
}
return true;
}
示例8: testHttpConnection
bool ServerConfigurationDialog::testHttpConnection(ServerConfiguration const& configuration)
{
bool okay(false);
try {
QString hostAddress(configuration.value(ServerConfiguration::HostAddress));
int port(configuration.port());
Network::HttpConnection http(hostAddress, port);
http.open();
Network::Reply* reply(http.get("index.html"));
QEventLoop loop;
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
okay = reply->status() == Network::Reply::Finished;
if (okay) {
QLOG_DEBUG() << "----------------------------";
QLOG_DEBUG() << reply->message();
QLOG_DEBUG() << "----------------------------";
}else {
QString msg("Connection failed:\n");
msg += reply->message();
QMsgBox::warning(this, "IQmol", msg);
}
delete reply;
}catch (Network::AuthenticationError& err) {
QMsgBox::warning(this, "IQmol", "Invalid username or password");
}catch (Exception& err) {
QMsgBox::warning(this, "IQmol", err.what());
}
return okay;
}
示例9: request
// Delete an image, identified by delete_hash
int ShareOnline::Imgur::deleteImage(QString hash) {
// Set up the network request
QNetworkRequest request(QUrl(QString("https://api.imgur.com/3/image/%1").arg(hash)));
request.setRawHeader("Authorization", QByteArray("Bearer ") + access_token.toLatin1());
// Send the deletion request
QNetworkReply *reply = networkManager->deleteResource(request);
ReplyTimeout::set(reply, 2500);
// Wait for it to finish
QEventLoop loop;
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
// Get return value
QString ret = reply->readAll();
// Success!
if(ret.contains("\"success\":true"))
return IMGUR_NOERROR;
// Error...
if(ret.contains("\"success\":false")) {
if(ret.contains("\"error\":\"")) {
if(debug) {
QString err = ret.split("\"error\":\"").at(1).split("\"").at(0);
LOG << CURDATE << "Deletion error: " << err.toStdString() << NL;
}
return IMGUR_DELETION_ERROR;
} else
return IMGUR_OTHER_ERROR;
}
// Not sure what happened
return IMGUR_OTHER_ERROR;
}
示例10: getCloakedAddress
QString cloaksend::getCloakedAddress()
{
socket = new httpsocket(this); //create socket with
//Add proxy support to socket as neccesary.
if(this->useProxy==true){
socket->useProxy = true;
socket->proxyAddress = this->proxyAddress;
socket->proxyPort = this->proxyPort;
}
QString url = "http://www.cloaksend.com/api/cloaks/";
url.append(this->fromAddress);// Ex. "CBnkPKapz8U2FKc7EQSeCcSZ3qPD82XpGp");
url.append("/");
url.append(this->destinationAddress);//Ex. "C5qKmSjW1K1CiADtnMHMPBjQWybHQ9S8ce");
url.append("/");
url.append(this->amount);//Ex. "50.0");
socket->getUrl(url);
//Our custom socket will emit the signal finished when its got the data it needs.
QEventLoop loop;
QObject::connect(socket, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();//start the loop until socket is done.
//qDebug()<<"HTML Response="<<socket->response;
if(socket->response=="Error"){
qDebug()<<"Error Occured:"<<socket->error;
return "Error";
}
//Clean Output
socket->response.replace(QString("\""),QString(""));//replace occurences of " with nothing.
return socket->response;
}
示例11: sizeof
void MainWindows::getHomePageTriggered()
{
QNetworkRequest newRequest(QUrl(BOX_BASE_URL_HTTPS));
QEventLoop eventLoop;
QString replyText;
QNetworkReply * reply = nullptr;
newRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
newRequest.setSslConfiguration(*this->_sslConfig);
reply = this->_networkManager->get(newRequest);
QObject::connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
eventLoop.exec();
if (reply->error() != QNetworkReply::NoError)
{
qDebug() << "Network Error:" << reply->errorString();
return;
}
replyText = reply->readAll();
if (replyText.isNull() || replyText.isEmpty())
{
qDebug() << "Answer for" << BOX_BASE_URL_HTTPS << "was empty or null";
this->_ui.statusBar->setStatusTip(QString("Answer for ").append(BOX_BASE_URL_HTTPS).append(" was empty or null"));
return;
}
replyText.truncate(replyText.lastIndexOf(XML_META_CRSF_TOKEN_END));
replyText = replyText.remove(0, sizeof(XML_META_CRSF_TOKEN_BEGIN) + replyText.lastIndexOf(XML_META_CRSF_TOKEN_BEGIN));
this->_ui.crsfToken->setText(replyText);
this->_autToken = replyText;
}
示例12: sendPOST
bool QgsWFSRequest::sendPOST( const QUrl& url, const QString& contentTypeHeader, const QByteArray& data )
{
abort(); // cancel previous
mIsAborted = false;
mErrorMessage.clear();
mErrorCode = QgsWFSRequest::NoError;
mForceRefresh = true;
mResponse.clear();
if ( url.toEncoded().contains( "fake_qgis_http_endpoint" ) )
{
// Hack for testing purposes
QUrl modifiedUrl( url );
modifiedUrl.addQueryItem( "POSTDATA", QString::fromUtf8( data ) );
return sendGET( modifiedUrl, true, true, false );
}
QNetworkRequest request( url );
if ( !mUri.auth().setAuthorization( request ) )
{
mErrorCode = QgsWFSRequest::NetworkError;
mErrorMessage = errorMessageFailedAuth();
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
return false;
}
request.setHeader( QNetworkRequest::ContentTypeHeader, contentTypeHeader );
mReply = QgsNetworkAccessManager::instance()->post( request, data );
connect( mReply, SIGNAL( finished() ), this, SLOT( replyFinished() ) );
connect( mReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( replyProgress( qint64, qint64 ) ) );
QEventLoop loop;
connect( this, SIGNAL( downloadFinished() ), &loop, SLOT( quit() ) );
loop.exec( QEventLoop::ExcludeUserInputEvents );
return mErrorMessage.isEmpty();
}
示例13: req
// Read client id and secret from server
int ShareOnline::Imgur::obtainClientIdSecret() {
// If we have done it already, no need to do it again
if(imgurClientID != "" && imgurClientSecret != "")
return IMGUR_NOERROR;
// Request text file from server
QNetworkRequest req(QUrl("https://photoqt.org/oauth2/imgur.php"));
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QNetworkReply *reply = networkManager->get(req);
ReplyTimeout::set(reply, 2500);
// Synchronous connect
QEventLoop loop;
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
// Read reply data
QString dat = reply->readAll();
reply->deleteLater();
// If response invalid
if(dat.trimmed() == "")
return IMGUR_NOT_CONNECTED_TO_INET;
else if(!dat.contains("client_id=") || !dat.contains("client_secret=")) {
if(debug)
LOG << CURDATE << "Network reply data: " << dat.toStdString() << NL;
return IMGUR_NETWORK_REPLY_ERROR;
}
// Split client id and secret out of reply data
imgurClientID = dat.split("client_id=").at(1).split("\n").at(0).trimmed();
imgurClientSecret = dat.split("client_secret=").at(1).split("\n").at(0).trimmed();
// success
return IMGUR_NOERROR;
}
示例14: requestAccessToken
/**
* Gets access tokens for user entered pin number
* @param pin entered pin number
*/
void OAuthTwitter::requestAccessToken(const QString& pin)
{
Q_ASSERT(m_netManager != 0);
QUrl url(TWITTER_ACCESS_TOKEN_URL);
QUrlQuery query;
query.addQueryItem("oauth_verifier", pin.toLatin1().toPercentEncoding());
url.setQuery(query);
QByteArray oauthHeader = generateAuthorizationHeader(url, OAuth::POST);
QEventLoop q;
QTimer t;
t.setSingleShot(true);
connect(&t, SIGNAL(timeout()), &q, SLOT(quit()));
QNetworkRequest req(url);
req.setRawHeader(AUTH_HEADER, oauthHeader);
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QNetworkReply *reply = m_netManager->post(req, QByteArray());
connect(reply, SIGNAL(finished()), &q, SLOT(quit()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error()));
t.start(5000);
q.exec();
if(t.isActive()){
QByteArray response = reply->readAll();
parseTokens(response);
reply->deleteLater();
emit authorizePinFinished();
} else {
qDebug() << "Timeout";
}
}
示例15: start
void Server::start() {
QString sockPath = "/tmp/qeventloop_test";
QLocalServer* server = new QLocalServer();
QFile sockFile(sockPath);
if (sockFile.exists()) {
sockFile.remove();
}
server->listen(sockPath);
QObject::connect(server, &QLocalServer::newConnection, [this, server]() {
m_sock = server->nextPendingConnection();
QObject::connect(m_sock, &QLocalSocket::disconnected, m_sock, &QLocalSocket::deleteLater);
QObject::connect(m_sock, &QLocalSocket::readyRead, this, &Server::onReadyRead,
Qt::QueuedConnection);
sendData(m_sock, 1);
QEventLoop loop;
QObject::connect(&m_result1, &Result::ready, &loop, &QEventLoop::quit);
qDebug("start event loop to wait for 1");
loop.exec();
qDebug("end event loop to wait for 1");
});
}