示例#1
0
    foreach (Sliver *sliver, slivers) {
        sliver->status = Sliver::STATUS_OFFLINE;
        sliverHash[sliver->name] = sliver;
        if (relayEnabled()) {
            installProgram(sliver);
            addSliverConnection(sliver);
        } else {
            if (sliver->IPv6.isEmpty()) {
                qDebug() << "No ip, getting address";
                getIpAddress(sliver);
                installProgram(sliver);
            } else {
                addSliverConnection(sliver);
                QTimer *timer = new QTimer(this);
                //if there's a specified IP address, give the connection some time before running the script setting things up.
                connect(timer, &QTimer::timeout, [timer, sliver, this]() {
                    qDebug() << "Checking connection status";
                    if (sliver->status == sliver->STATUS_OFFLINE) {
                        qDebug() << "Still offline, reinstalling";
                        installProgram(sliver);
                    }
                    timer->stop();
                    timer->deleteLater();
                });
                timer->start(3000);
            }
        }

        QTimer *timer = new QTimer(this);


        //Will try to connect as long as the sliver is not connected
        connect(timer, &QTimer::timeout, [timer, sliver, this]() {
            if (sliver->status != sliver->STATUS_CONNECTED) {
                qDebug() << "Retryign connection";
                addSliverConnection(sliver);
            } else {
                timer->stop();
                timer->deleteLater();
            }

            static int time = 0;
            time+=3;
            //if (time > 35) {
             //   shutDownNodeprogs(QList<Sliver*>() << sliver);
              //  installProgram(sliver);
               // time = 0;
           // }
        });
        timer->start(3000);
    }
示例#2
0
  bool Irc::Disconnect()
  {
    //quick out
    if(!m_connected)
      return true;

    //create timer connected to the timeout slot
    QTimer timer;
    connect(&timer,SIGNAL(timeout()),this,SLOT(OnTimeout()));

    //start timer
    timer.start(CONNECTION_TIMEOUT);

    //disconnect from host
    m_socket.disconnectFromHost();

    if(m_socket.state() != 0) // if 0, then already disconnected
      m_eventloop.exec();

    //stop timer
    timer.stop();
    //disconnect timer from timeout slot
    disconnect(&timer,SIGNAL(timeout()), this,SLOT(OnTimeout()));

    return !m_connected;    //return inverse of m_connected. eg. if m_connected false then the function succeeded
  }
示例#3
0
  bool Irc::Connect()
  {
    //quick out
    if(m_connected)
      return true;

    //create timer connected to the timeout slot
    QTimer timer;
    connect(&timer,SIGNAL(timeout()),this,SLOT(OnTimeout()));
    
    //start timer
    timer.start(CONNECTION_TIMEOUT);

    //connect to host
    m_socket.connectToHost(m_host, m_port);

    if(m_socket.state() < 3) // if smaller then not yet connected
      m_eventloop.exec();

    //stop timer
    timer.stop();
    //disconnect timer from timeout slot
    disconnect(&timer,SIGNAL(timeout()), this,SLOT(OnTimeout()));

    return m_connected;
  }
示例#4
0
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();
    }
}
示例#5
0
//virtual
void PromiseTimer::cancel_me()
{
	if(!isActivating()) {
    timer.stop();
		delete this;
	}
}
示例#6
0
int main(int argc, char *argv[]) {
#ifndef WIN32
  XInitThreads();
#endif
  QApplication app(argc, argv);
  MyWidget *window = new MyWidget;

  //see my_widget.h for controller and cache creation

  window->show();

  window->update();
  QTimer *timer = new QTimer(window);
  QObject::connect(timer, SIGNAL(timeout()), window, SLOT(update()));
  timer->start(2000);

  QTimer *timer1 = new QTimer(window);
  QObject::connect(timer1, SIGNAL(timeout()), window, SLOT(updateGL()));
  timer1->start(20);

  QTimer *timer2 = new QTimer(window);
  QObject::connect(timer2, SIGNAL(timeout()), window, SLOT(close()));
  timer2->start(20000);

  app.exec();
  timer->stop();
  timer1->stop();
  timer2->stop();

  QTest::qWait(2000);
  qDebug("main program calling destruction");
  return 0;
}
void PictureFlowAnimator::stop(int slide)
{
    step = 0;
    target = slide;
    frame = slide << 16;
    animateTimer.stop();
}
示例#8
0
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();
    }
}
示例#9
0
void XFoilAnalysisDlg::Analyze()
{
	m_pctrlCancel->setText(tr("Cancel"));
	m_pctrlSkip->setEnabled(true);

	//all set to launch the analysis

	//create a timer to update the output at regular intervals
	QTimer *pTimer = new QTimer;
	connect(pTimer, SIGNAL(timeout()), this, SLOT(OnProgress()));
	pTimer->setInterval(QXDirect::s_TimeUpdateInterval);
	pTimer->start();

	//Launch the task

	m_pXFoilTask->run();

	pTimer->stop();
	delete pTimer;

	OnProgress();
	m_pXFoilTask->m_OutStream.flush();

	m_bErrors = m_pXFoilTask->m_bErrors;
	if(m_bErrors)
	{
		m_pctrlTextOutput->insertPlainText(tr(" ...some points are unconverged"));
		m_pctrlTextOutput->ensureCursorVisible();
	}

	m_pctrlCancel->setText(tr("Close"));
	m_pctrlSkip->setEnabled(false);
	update();

}
示例#10
0
bool Utils::sendBlockingNetRequest(const QUrl& theUrl, QString& reply)
{
    QNetworkAccessManager manager;
    QEventLoop q;
    QTimer tT;

    manager.setProxy(M_PREFS->getProxy(QUrl("http://merkaartor.be")));

    tT.setSingleShot(true);
    connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
    connect(&manager, SIGNAL(finished(QNetworkReply*)),
            &q, SLOT(quit()));

    QNetworkReply *netReply = manager.get(QNetworkRequest(theUrl));

    tT.start(M_PREFS->getNetworkTimeout());
    q.exec();
    if(tT.isActive()) {
        // download complete
        tT.stop();
    } else {
        return false;
    }

    reply = netReply->readAll();
    return true;
}
// Callback when media keys are pressed
void MediakeyCaptureItemPrivate::MrccatoCommand(TRemConCoreApiOperationId aOperationId,
                                                TRemConCoreApiButtonAction aButtonAct)
{
    if (aButtonAct == ERemConCoreApiButtonRelease) {
        m_timer->stop();
        m_volumeDownPressed = false;
        m_volumeUpPressed = false;
        return;
    }

    switch (aOperationId) {
    case ERemConCoreApiVolumeUp:
        m_volumeUpPressed = true;
        m_volumeDownPressed = false;
        d_ptr->increaseVolume();
        if (aButtonAct == ERemConCoreApiButtonPress) m_timer->start();
        return;
    case ERemConCoreApiVolumeDown:
        m_volumeDownPressed = true;
        m_volumeUpPressed = false;
        d_ptr->decreaseVolume();
        if (aButtonAct == ERemConCoreApiButtonPress) m_timer->start();
        break;
    default:
        m_volumeDownPressed = false;
        m_volumeUpPressed = false;
        return;
    }
}
示例#12
0
文件: main.cpp 项目: ypvk/WebSearch
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();
}
QVariantMap QgsFileDownloaderAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
  mFeedback = feedback;
  QString url = parameterAsString( parameters, QStringLiteral( "URL" ), context );
  QString outputFile = parameterAsFileOutput( parameters, QStringLiteral( "OUTPUT" ), context );

  QEventLoop loop;
  QTimer timer;
  QgsFileDownloader *downloader = new QgsFileDownloader( QUrl( url ), outputFile, QString(), true );
  connect( mFeedback, &QgsFeedback::canceled, downloader, &QgsFileDownloader::cancelDownload );
  connect( downloader, &QgsFileDownloader::downloadError, this, &QgsFileDownloaderAlgorithm::reportErrors );
  connect( downloader, &QgsFileDownloader::downloadProgress, this, &QgsFileDownloaderAlgorithm::receiveProgressFromDownloader );
  connect( downloader, &QgsFileDownloader::downloadExited, &loop, &QEventLoop::quit );
  connect( &timer, &QTimer::timeout, this, &QgsFileDownloaderAlgorithm::sendProgressFeedback );
  downloader->startDownload();
  timer.start( 1000 );

  loop.exec();

  timer.stop();
  bool exists = QFileInfo( outputFile ).exists();
  if ( !feedback->isCanceled() && !exists )
    throw QgsProcessingException( tr( "Output file doesn't exist." ) );

  QVariantMap outputs;
  outputs.insert( QStringLiteral( "OUTPUT" ), exists ? outputFile : QString() );
  return outputs;
}
示例#14
0
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;
}
示例#15
0
void InputDaemon::quit()
{
    stopped = true;

    // Wait for SDL to finish. Let worker destructor close SDL.
    // Let InputDaemon destructor close thread instance.
    if (graphical)
    {
        QEventLoop q;
        QTimer temptime;
        connect(eventWorker, SIGNAL(finished()), &q, SLOT(quit()));
        connect(&temptime, SIGNAL(timeout()), &q, SLOT(quit()));

        eventWorker->stop();
        temptime.start(1000);
        q.exec();
        temptime.stop();
    }
    else
    {
        eventWorker->stop();
    }

    delete eventWorker;
    eventWorker = 0;
}
示例#16
0
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();
    }
}
示例#17
0
void OculusWin32DisplayPlugin::stop() {
    _context->makeCurrent(_window);

    if (_sceneSwapFbo) {
        delete _sceneSwapFbo;
        _sceneSwapFbo = nullptr;
    }

    if (_mirrorFbo) {
        delete _mirrorFbo;
        _mirrorFbo = nullptr;
    }

    _context->doneCurrent();

    _timer.stop();
    _window->deleteLater();
    _window = nullptr;
    _context->deleteLater();
    _context = nullptr;

    if (_hmd) {
        ovr_Destroy(_hmd);
        _hmd = nullptr;
    }
    ovr_Shutdown();

}
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();
}
示例#19
0
void CQplayerGUI::touchAdjust(QMouseEvent *e)
{
    static int init = 0;
    static QTimer timer;
    if(init == 0){
        init++;
        timer.setSingleShot(true);
        timer.setInterval(1000);
        connect(&timer,SIGNAL(timeout()),this,SLOT(clickStateReset()));
    }
    if(ui->frameMovie->geometry() != media->row_rect)
        return;
    qDebug()<<ui->logWidget->geometry()<<"    "<<e->globalPos();
    if(!ui->logWidget->geometry().contains(e->globalPos()))
        return;
    clickCnt++;
    timer.start();
    if(clickCnt >= 3) {
        clickCnt = 0;
        timer.stop();
        system("rm /etc/pointercal.xinput  /.pointercal/ -rf");
		stop();
        system("xinput_calibrator_once.sh &");
    }
}
void MainWindow::on_updateCheckBox_clicked()
{
    if (ui->updateCheckBox->checkState())
        updateTimer.start(ui->updateSpinBox->value());
    else
        updateTimer.stop();
}
示例#21
0
void Operation::perform()
{
    pd->setValue(steps);
    //... perform one percent of the operation
    steps++;
    if (steps > pd->maximum())
        t->stop();
}
示例#22
0
void QFeedbackImmersion::killTimerForHandle(VibeInt32 handle)
{
    QTimer* t = effectTimers.take(handle);
    if (t) {
        t->stop();
        delete t;
    }
}
示例#23
0
文件: searchbar.cpp 项目: KDE/kdepim
    void triggerTimer()
    {
        if (timer.isActive()) {
            timer.stop();
        }

        timer.start(200);
    }
示例#24
0
void MainWindow::LoadFile()
{

    if (FileFormatPluginList.size()) {


        QString FileName = QFileDialog::getOpenFileName(this, tr("Open File"),
                                                     "",
                                                     FileFormatPluginList[0]->getFormatDescription());

        //test();
        // Create a progress dialog.
            QProgressDialog dialog;

            dialog.setLabelText(QString("Загрузка данных из файла"));

            // Create a QFutureWatcher and connect signals and slots.
            QFutureWatcher<void> futureWatcher;
            QTimer timer;
            connect(&timer, SIGNAL(timeout()), this, SLOT(updateProgress()));
            timer.start(1000);
            QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset()));
            QObject::connect(&dialog, SIGNAL(canceled()), SLOT(cancelOperation()));
            QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel()));
            QObject::connect(this, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int)));

            //extern void FileFormatPluginList[0]->getDataFromChannel(channel,(qint8*)data);


            QFuture<void> future = QtConcurrent::run(FileFormatPluginList[0], &FileReadInterface::LoadFile, FileName);

            // Start the computation.
            futureWatcher.setFuture(future);

            // Display the dialog and start the event loop.
            dialog.exec();

            futureWatcher.waitForFinished();
            dialog.setValue(100);
            dialog.hide();


            timer.stop();



        cube= FileFormatPluginList[0]->getCube();


        QList<double> list = cube->GetListOfChannels();




        foreach(double l , list) {
            ui->ChannelListWidget->addItem(QString("%1").arg(l));
        }
// Core 
bool FilterWebExportVMustPlugin::applyFilter(QAction *filter, MeshDocument &md, RichParameterSet & /*parent*/, vcg::CallBackPos * cb)
{
	if (ID(filter) == FP_WEB_EXPORT)
	{
		CMeshO &m=md.mm()->cm;

		QNetworkAccessManager NAManager;

		// STEP 1: check if the server works (by requesting the list of application templates)
		// (note that this list is not used)
		QUrl urlTest ("http://pipeline.v-must.net/api/v1/bundles");

		QNetworkRequest request1(urlTest);

		QNetworkReply *reply1 = NAManager.get(request1);
		QTimer timer;
		timer.setSingleShot(true);
		timer.start(5000);

		QEventLoop eventLoop;
		connect(reply1, SIGNAL(finished()), &eventLoop, SLOT(quit()));
		connect(&timer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
		eventLoop.exec();   // block the http request for 5 seconds

		delete reply1;

		if (timer.isActive())
		{
			timer.stop();

			// STEP 2: preparing the bucket for the processing

			QUrl urlBucket("http://pipeline.v-must.net/api/v1/buckets");
			QNetworkRequest request2(urlBucket);
			request2.setRawHeader("Accept", "application/json");
			request2.setRawHeader("Accept-Encoding", "gzip, deflate, compress");
			request2.setRawHeader("Content-Type", "application/octet-stream");
			request2.setRawHeader("Host", "pipelineserver.ltd");
			request2.setRawHeader("X-Filename", "test.ply");

			QNetworkReply *reply2 = NAManager.get(request2);
			connect(reply2, SIGNAL(finished()), &eventLoop, SLOT(quit()));
			eventLoop.exec();   // block the http request

			// STEP 3: launch the processing according to the selected template
		}
		else
		{
			QMessageBox::warning(0, tr("V-Must CIF API"), tr("Server is time out. Please, re-try later."));
		}



	}

	return true;
}
示例#26
0
 Q_SLOT void lookupResult(const QHostInfo & host) {
    m_timer.stop();
    if (host.error() != QHostInfo::NoError)
       return hasResult(Error);
    for (auto ifAddr : QNetworkInterface::allAddresses())
       if (host.addresses().contains(ifAddr))
          return hasResult(Local);
    return hasResult(NonLocal);
 }
示例#27
0
文件: maemo_icd.cpp 项目: RS102839/qt
uint IcdPrivate::state(QString& service_type, uint service_attrs,
		       QString& service_id, QString& network_type,
		       uint network_attrs, QByteArray& network_id,
		       IcdStateResult& state_result)
{
    QTimer timer;
    QVariant reply;
    uint total_signals;
    QVariantList vl;

    clearState();

    reply = mDBus->call(ICD_DBUS_API_STATE_REQ,
			service_type, service_attrs, service_id,
			network_type, network_attrs, network_id);
    if (reply.type() != QVariant::List)
        return 0;
    vl = reply.toList();
    if (vl.isEmpty())
        return 0;
    reply = vl.first();
    total_signals = reply.toUInt();
    if (!total_signals)
        return 0;

    timer.setSingleShot(true);
    timer.start(timeout);

    mInterface.clear();
    while (timer.isActive() && mInterface.isEmpty()) {
        QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);

	if (mSignal != ICD_DBUS_API_STATE_SIG) {
            mInterface.clear();
	    continue;
	}
    }

    timer.stop();

    if (mError.isEmpty()) {
        if (!mArgs.isEmpty()) {
	    if (mArgs.size()>2)
	        get_state_all_result(mArgs, state_result);
	    else {
	        // We are not connected as we did not get the status we asked
	        return 0;
	    }
	}
    } else {
        qWarning() << "Error:" << mError;
    }

    // The returned value should be one because we asked for one state
    return total_signals;
}
bool NetBalanceGetter::get_timeleft(){
	QNetworkReply* reply;

	QTimer timeout;
	QEventLoop waitLoop;
	QObject::connect(&timeout, SIGNAL(timeout()), &waitLoop, SLOT(quit()) );

	timeout.setSingleShot(true);
	timeout.start(timeout_ms);
	reply = manager->get(QNetworkRequest(QUrl("http://cabinet.telecom.mipt.ru/stats/?from=11.05.2012&to=11.05.2013")));
	QObject::connect(reply, SIGNAL(finished()), &waitLoop, SLOT(quit()));
	waitLoop.exec();
	
	if( timeout.isActive() && (reply->error() == QNetworkReply::NoError) ) {
		timeout.stop();

		QString page_body = reply->readAll();
		const QString separator = "<i>";
		QString stat;
		
		int index = 0;
		int pos = page_body.indexOf(separator) + QString(separator).length();
		pos = page_body.indexOf(separator,pos) + QString(separator).length();
		if(pos < 0){
			//emit failed();
			MessageBox(NULL,NULL,NULL,2);
			return false;
		};

		do{
			if( (pos + index) >= page_body.size()){
				emit failed();
				return false;
			}
			stat.append(page_body[pos+index]);
			index++;
		}while(page_body[pos+index] != '<');
		/*stat.append(".");
		stat.append(page_body[pos+index+1]);
		stat.append(page_body[pos+index+2]);
		stat.append(page_body[pos+index+2]);*/
		bool ok = false;
		stat.toDouble(&ok);		
		if(!ok){
			emit failed();
			MessageBox(NULL,stat.toStdWString().data(),NULL,2);
			return false;
		}
		emit new_timeleft(stat.toDouble());
		return true;
	}else
	{
		//emit failed();
		return false;
	}
}
示例#29
0
文件: taxi.cpp 项目: joonahn/gakchae
void Taxi::keyPressEvent(QKeyEvent *event)
{
    if(event->key() == Qt::Key_Space)
    {
        if(judge==0)
        {
            game->taxi->setPos(50,315);
            game->taxi->setScale(1);
            light->setScale(1);
            light->setPos(25,285);
            scene->removeItem(game->info);
            game->money->starttimer();
            game->taxi_distance->starttimer();
            game->timer->start(2000);
            game->music->play();
            judge++;
        }

        jumpsound->play();
        QTimer *timer = new QTimer();

        if(up_down==2)//during jump can't move
        {
            up_down=1;
            connect(timer,SIGNAL(timeout()),this,SLOT(move()));
            timer->start(20);
            if(pos().y() == 315)
            {
                if(taxistop==0)
                {
                    timer->stop();
                    delete timer;
                    taxistop=1;
                }
            }
        }
    }
    if(pos().y() <400)//during jump shoot bullet
    {
        if(event->key() == Qt::Key_A)
        {
            Bullet * bullet = new Bullet();
            bullet->setPos(x()+50,y());
            scene->addItem(bullet);
            if(bulletsound->state()==QMediaPlayer::PlayingState)
            {
                bulletsound->setPosition(0);
            }
            else if(bulletsound->state()==QMediaPlayer::StoppedState)
            {
                bulletsound->play();
            }
        }
    }

}
示例#30
0
void MainWindow::sleep(long time)
{
        QEventLoop loop;
        QTimer timer;
        timer.setSingleShot(true);
        QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
        timer.start(time);
        loop.exec();
        timer.stop();
}