本文整理汇总了C++中QTimer::setSingleShot方法的典型用法代码示例。如果您正苦于以下问题:C++ QTimer::setSingleShot方法的具体用法?C++ QTimer::setSingleShot怎么用?C++ QTimer::setSingleShot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTimer
的用法示例。
在下文中一共展示了QTimer::setSingleShot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: postSynchronously
void CometClient::postSynchronously(const QString &requestUrlString, const QString &postDataString, int requestIdentifier, int timeoutMilliseconds) {
QUrl requestUrl(requestUrlString);
QNetworkRequest request(requestUrl);
request.setAttribute(QNetworkRequest::User, QVariant(requestIdentifier));
request.setRawHeader("X-Requested-With", "XMLHttpRequest");
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QByteArray data;
data.append(postDataString);
QNetworkReply *reply = nam->post(request, data);
requestsMade.insert(reply);
QTimer timer; //the timer handles timeout event
timer.setSingleShot(true);
QEventLoop loop;
QObject::connect(reply, SIGNAL(readyRead()), &loop, SLOT(quit()));
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
timer.start(timeoutMilliseconds);
loop.exec(QEventLoop::ExcludeUserInputEvents);
if(timer.isActive()) {
timer.stop();
} else {
qDebug() << "postSynchronously() timeout occured";
//reply->abort();
}
}
示例2: wheelEvent
void smallPictureView::wheelEvent(QWheelEvent *e){
if(!allImgs.isEmpty()){
if (e->orientation() == Qt::Vertical) {
if(wheelFlag == 0){
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(wheelChangeImg()));
timer->start(400);
timer->setSingleShot(true);//once
}
int numDegrees = e->delta() / 8;//滚动的角度,*8就是鼠标滚动的距离
int numSteps = numDegrees / 15;//滚动的步数,*15就是鼠标滚动的角度
wheelFlag += numSteps;
//selectedNum-=wheelFlag;
selectedNum -= numSteps;
if(selectedNum<0){
selectedNum = imgNum-1;
}else if(selectedNum>=imgNum){
selectedNum = 0;
}
// qDebug()<<"垂直滚动 = "<<numSteps;//垂直滚动
currentfile = allPixItem.at(selectedNum)->data(1001).toString();
emit sendToDisplayImg(all_Qimg[selectedNum],all_size[selectedNum]);
} else {
qDebug()<<"水平滚动 = "; //水平滚动
}
e->accept(); //接收该事件
}else{
QMessageBox message(QMessageBox::NoIcon, "提示", "请先选择图片文件!");
message.setIconPixmap(QPixmap("../2.png"));
message.exec();
}
}
示例3: StopUpdateCheck
void UpdaterPrivate::StopUpdateCheck(int delay, bool async) {
if (main_process == nullptr || main_process->state() == QProcess::NotRunning) {
return;
}
if (delay > 0) {
main_process->terminate();
if (async) {
QTimer* timer = new QTimer(this);
timer->setSingleShot(true);
connect(timer, &QTimer::timeout, [=]() {
StopUpdateCheck(0, false);
timer->deleteLater();
});
timer->start(delay);
} else {
if (!main_process->waitForFinished(delay)) {
main_process->kill();
main_process->waitForFinished(100);
}
}
} else {
main_process->kill();
main_process->waitForFinished(100);
}
}
示例4: start_install
void BootConfig::start_install() {
bool to_stdout = false;
QStringList args;
xterm->setProcessChannelMode(QProcess::ForwardedChannels);
xterm->setStandardInputFile(QProcess::nullDevice());
if (!to_stdout) {
args.append("-into");
args.append(QString("%1").arg(ui->xterm->winId()));
args.append("-geometry");
args.append("484x316");
args.append("-e");
args.append("nixos-install");
}
args.append("--root");
args.append("/mnt");
connect(xterm,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(install_finished(int,QProcess::ExitStatus)));
if (to_stdout) {
xterm->start("nixos-install",args);
} else {
xterm->start("xterm",args);
}
QTimer *foo = new QTimer();
connect(foo,SIGNAL(timeout()),this,SLOT(debug1()));
foo->setInterval(400 * 1000);
foo->setSingleShot(true);
foo->start();
}
示例5: ReleaseMessage
void Btowngtw::receiveCMD(QString value, QString key) {
qDebug() << m_gtwID << " Receive command from Gateway: " << value;
PlantMessage myMsg;
SysError theSysError;
if(OpenMsg::parse(value, myMsg)) {
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(stopTimer()));
timer->setSingleShot(true);
int msgID = qrand() % ((MAX_TIMER_ID + 1) - 0) + 0;
m_timeoutMap.insert(msgID, key);
timer->setProperty(TIMER_ID.toStdString().c_str(), msgID);
timer->setProperty(TYPE.toStdString().c_str(), sender()->property(TYPE.toStdString().c_str()).toString());
timer->setProperty(FRAME_TYPE.toStdString().c_str(), OpenMsg::getFrameType(value));
qDebug() << " timer getProperty: " << sender()->property(TYPE.toStdString().c_str()).toString() << " " << timer->property(TYPE.toStdString().c_str()).toString();
timer->start(TIMEOUT);
qDebug() << m_gtwID << " Parsing ok, emit sendCommand Signal";
myMsg.setSourceAddr(QPair<QString, QString>(PlantMessage::EXTERNAL, key), true);
myMsg.setDestAddr(QPair<QString, QString>(PlantMessage::INTERNAL, PlantMessage::DEVICE), true);
myMsg.setType(sender()->property(TYPE.toStdString().c_str()).toString());
myMsg.setId(msgID);
emit ReleaseMessage(myMsg, theSysError);
}
else {
qDebug() << m_gtwID << " Receive command from Gateway is WRONG FORMAT";
}
}
示例6: mouseReleaseEvent
void CQplayerGUI::mouseReleaseEvent(QMouseEvent *e)
{
static int init = 0;
static QTimer timer;
static QPoint p;
touchAdjust(e);
if(init == 0){
init++;
timer.setSingleShot(true);
timer.setInterval(1000);
connect(&timer,SIGNAL(timeout()),this,SLOT(clickStateReset()));
}
if(!ui->frameMovie->geometry().contains(e->globalPos()))
return;
clickCnt++;
if(clickCnt == 1){ //第一次点击
p = e->pos();
timer.start();
}
else { //第二次点击
clickCnt = 0;
timer.stop();
if((e->pos() - p).manhattanLength() < 200)//两次点击距离10pix之内为有效双击
media->screenNormal();
}
}
示例7: contentChanged
void QgsComposerLabel::contentChanged()
{
if ( mHtmlState )
{
const QString textToDraw = displayText();
//mHtmlLoaded tracks whether the QWebPage has completed loading
//its html contents, set it initially to false. The loadingHtmlFinished slot will
//set this to true after html is loaded.
mHtmlLoaded = false;
const QUrl baseUrl = QUrl::fromLocalFile( mComposition->project()->fileInfo().absoluteFilePath() );
mWebPage->mainFrame()->setHtml( textToDraw, baseUrl );
//For very basic html labels with no external assets, the html load will already be
//complete before we even get a chance to start the QEventLoop. Make sure we check
//this before starting the loop
if ( !mHtmlLoaded )
{
//Setup event loop and timeout for rendering html
QEventLoop loop;
//Connect timeout and webpage loadFinished signals to loop
connect( mWebPage, SIGNAL( loadFinished( bool ) ), &loop, SLOT( quit() ) );
// Start a 20 second timeout in case html loading will never complete
QTimer timeoutTimer;
timeoutTimer.setSingleShot( true );
connect( &timeoutTimer, SIGNAL( timeout() ), &loop, SLOT( quit() ) );
timeoutTimer.start( 20000 );
// Pause until html is loaded
loop.exec();
}
}
示例8: get
bool Spider::get(NetWorker *instance,QString url){
QString address1 = "http://192.168.60.131:9200/bcc/_search?q=url:\"";
QString address2 = "http://192.168.60.132:9200/bcc/_search?q=url:\"";
QString address3 = "http://192.168.60.133:9200/bcc/_search?q=url:\"";
QString address4 = "http://192.168.60.134:9200/bcc/_search?q=url:\"";
//QString url = "http://192.168.60.134:9200/bcc/_search?q=url:\"http://www.lagou.co/jobs/218581.html?source=search\"";
int count = rand();
qDebug()<<address1+url+"\"";
if(count%4==0){
instance->get(address1+url+"\"");
}else if(count%4==1){
instance->get(address2+url+"\"");
}else if(count%4==2){
instance->get(address3+url+"\"");
}else {
instance->get(address4+url+"\"");
};
QEventLoop eventLoop;
QTimer timer;
timer.setSingleShot(true);
QObject::connect(instance, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
QObject::connect(&timer,SIGNAL(timeout()),&eventLoop,SLOT(quit()));
timer.start(3000);
eventLoop.exec(); //block until finish
if(timer.isActive()){
timer.stop();
//return false;
}
return instance->flag;
}
示例9: readTransferServerMessage
void OMIProxy::readTransferServerMessage(QString message)
{
// send the message to interactive simulation widget
/* QTimer and QSignalMapper are the best :) */
QSignalMapper *pSingnalMapper = new QSignalMapper;
QTimer *pTimer = new QTimer;
pTimer->setSingleShot(true);
pTimer->setInterval(1000); // 1 sec
connect(pTimer, SIGNAL(timeout()), pSingnalMapper, SLOT(map()));
pSingnalMapper->setMapping(pTimer, message);
connect(pSingnalMapper, SIGNAL(mapped(QString)), mpInteractiveSimulationTab, SLOT(recievedResult(QString)));
pTimer->start();
// move the cursor down before adding to the logger.
QTextCursor textCursor = mpTransferServerTextEdit->textCursor();
textCursor.movePosition(QTextCursor::End);
mpTransferServerTextEdit->setTextCursor(textCursor);
// log the message
mpTransferServerTextEdit->setCurrentFont(QFont("Times New Roman", 10, QFont::Bold, false));
mpTransferServerTextEdit->insertPlainText(QString(">>---- Message Received : ").append(QTime::currentTime().toString()).append(" ----"));
mpTransferServerTextEdit->setCurrentFont(QFont("Times New Roman", 10, QFont::Normal, false));
mpTransferServerTextEdit->insertPlainText(QString("\n>> ").append(message).append("\n"));
// move the cursor
textCursor.movePosition(QTextCursor::End);
mpTransferServerTextEdit->setTextCursor(textCursor);
}
示例10: stop
void StratumClient::stop() {
QEventLoop waitLoop;
QTimer disconnectTimer;
disconnectTimer.setSingleShot(true);
disconnectTimer.setInterval(RECONNECT_TIMER_INTERVAL);
connect(m_socket, &QTcpSocket::disconnected, &waitLoop, &QEventLoop::quit);
connect(&disconnectTimer, &QTimer::timeout, &waitLoop, &QEventLoop::quit);
m_socket->disconnectFromHost();
disconnectTimer.start();
if (m_socket->state() != QTcpSocket::UnconnectedState) {
waitLoop.exec();
}
if (!disconnectTimer.isActive()) {
m_socket->abort();
disconnectTimer.stop();
}
if (m_reconnectTimerId != -1) {
killTimer(m_reconnectTimerId);
m_reconnectTimerId = -1;
}
if (m_responseTimerId != -1) {
killTimer(m_responseTimerId);
m_responseTimerId = -1;
}
m_activeRequestMap.clear();
m_currentSessionId.clear();
QWriteLocker lock(&m_jobLock);
m_currentJob = Job();
}
示例11: post
void Spider::post(const QMap<QString, QVariant> &map,NetWorker *instance){
QString address1 = "http://192.168.60.131:9200/bcc/1";
QString address2 = "http://192.168.60.132:9200/bcc/1";
QString address3 = "http://192.168.60.133:9200/bcc/1";
QString address4 = "http://192.168.60.134:9200/bcc/1";
QJsonDocument doc=QJsonDocument::fromVariant(QVariant(map));
QByteArray j=doc.toJson();
QString result(j);
qDebug()<<result;
int count = rand();
if(count%4==0){
instance->post(QUrl(address1),j);
}else if(count%4==1){
instance->post(QUrl(address2),j);
}else if(count%4==2){
instance->post(QUrl(address3),j);
}else {
instance->post(QUrl(address4),j);
}
QEventLoop eventLoop;
QTimer timer;
timer.setSingleShot(true);
QObject::connect(instance, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
QObject::connect(&timer,SIGNAL(timeout()),&eventLoop,SLOT(quit()));
timer.start(2000);
eventLoop.exec(); //block until finish
if(timer.isActive()){
timer.stop();
}
}
示例12: set_icon
void Authorization::set_icon(const bool &isReset, const bool &hasFailed)
{
if (hasFailed)
ui->b_reset->setIcon(QIcon(":/icon-error"));
else
ui->b_reset->setIcon(QIcon(":/icon-ok"));
ui->b_reset->setEnabled(true);
QTimer *timer = new QTimer(this);
timer->setSingleShot(true);
timer->start(1000);
if (hasFailed)
if (isReset)
QObject::connect(timer, &QTimer::timeout, [=] { ui->b_reset->setIcon(QIcon(":/icon-reset")); });
else
QObject::connect(timer, &QTimer::timeout, [=] {
ui->b_reset->setIcon(QIcon(":/icon-reset-dark"));
ui->b_reset->setDisabled(true);
});
else
if (isReset)
QObject::connect(timer, &QTimer::timeout, [=] {
ui->b_reset->setIcon(QIcon(":/icon-reset-dark"));
ui->b_reset->setDisabled(true);
});
else
QObject::connect(timer, &QTimer::timeout, [=] { ui->b_reset->setIcon(QIcon(":/icon-reset")); });
}
示例13: search
void HostipRunner::search( const QString &searchTerm, const GeoDataLatLonBox & )
{
if( !searchTerm.contains('.') ) {
// Simple IP/hostname heuristic to avoid requests not needed:
// String must contain at least one dot.
slotNoResults();
}
else {
QEventLoop eventLoop;
QTimer timer;
timer.setSingleShot( true );
timer.setInterval( 15000 );
connect( &timer, SIGNAL(timeout()),
&eventLoop, SLOT(quit()));
connect( this, SIGNAL(searchFinished(QVector<GeoDataPlacemark*>)),
&eventLoop, SLOT(quit()) );
// Lookup the IP address for a hostname, or the hostname if an IP address was given
QHostInfo ::lookupHost( searchTerm, this, SLOT(slotLookupFinished(QHostInfo)));
timer.start();
eventLoop.exec();
}
}
示例14: req
QString ConnectionTester::Private::publicIpAddress() const
{
QString ret;
QEventLoop eventLoop;
QNetworkAccessManager mgr;
QTimer timer;
timer.setSingleShot(true);
QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
QObject::connect(&timer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
QNetworkRequest req(QUrl(QString("http://icanhazip.com")));
QNetworkReply *reply = mgr.get(req);
timer.start(10000);
eventLoop.exec();
if (reply->error() == QNetworkReply::NoError)
{
ret = QString(reply->readAll()).trimmed();
}
delete reply;
return ret;
}
示例15: testGetRequest
void testGetRequest()
{
QString url = "http://m.baidu.com/s?word=abc&ts=1223145&rq=ab";
QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager();
QNetworkRequest request;
request.setUrl(QUrl(url));
request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
//request.setRawHeader("Accept-Encoding", "gzip, deflate, sdch");
request.setRawHeader("Accept-Language", "h-CN,zh;q=0.8");
request.setRawHeader("Host", "m.baidu.com");
request.setRawHeader("Referer", "http://m.baidu.com");
request.setRawHeader("Connection", "keep-alive");
request.setRawHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36");
QNetworkReply* reply = networkAccessManager->get(request);
QEventLoop loop;
NetWorkCookieJar* cookieJar = new NetWorkCookieJar(networkAccessManager);
networkAccessManager->setCookieJar(cookieJar);
QTimer timer;
timer.setSingleShot(true);
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
timer.start(5000);
loop.exec();
timer.stop();
qDebug() << request.rawHeaderList();
qDebug() << reply->readAll();
qDebug() << cookieJar->getCookies();
networkAccessManager->deleteLater();
reply->deleteLater();
}