当前位置: 首页>>代码示例>>C++>>正文


C++ QElapsedTimer::restart方法代码示例

本文整理汇总了C++中QElapsedTimer::restart方法的典型用法代码示例。如果您正苦于以下问题:C++ QElapsedTimer::restart方法的具体用法?C++ QElapsedTimer::restart怎么用?C++ QElapsedTimer::restart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QElapsedTimer的用法示例。


在下文中一共展示了QElapsedTimer::restart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: on_action_write_triggered

void MainWindow::on_action_write_triggered()
{
    QString xlsFile = QFileDialog::getExistingDirectory(this);
    if(xlsFile.isEmpty())
        return;
    xlsFile += "/excelRWByCztr1988.xls";
    QElapsedTimer timer;
    timer.start();
    if(m_xls.isNull())
        m_xls.reset(new ExcelBase);
    m_xls->create(xlsFile);
    qDebug()<<"create cost:"<<timer.elapsed()<<"ms";timer.restart();
    QList< QList<QVariant> > m_datas;
    for(int i=0;i<1000;++i)
    {
        QList<QVariant> rows;
        for(int j=0;j<100;++j)
        {
            rows.append(i*j);
        }
        m_datas.append(rows);
    }
    m_xls->setCurrentSheet(1);
    timer.restart();
    m_xls->writeCurrentSheet(m_datas);
    qDebug()<<"write cost:"<<timer.elapsed()<<"ms";timer.restart();
    m_xls->save();
}
开发者ID:KoN-Fantazia,项目名称:czyBlog,代码行数:28,代码来源:MainWindow.cpp

示例2: onStateChartCycle

void DefaultStateChartDriver::onStateChartCycle()
{

    //void
    m_sc->runCycle();
    if (m_sc->getDefaultSCI()->isRaised_heartbeat())
    {
    	static QElapsedTimer timer;
    	if (timer.isValid())
    		qDebug() << "heartbeat :" << timer.elapsed() << "/ 1000";
        timer.restart();
    }
    if (m_sc->getDefaultSCI()->isRaised_footstomp())
    {
    	static QElapsedTimer timer;
    	if (timer.isValid())
    		qDebug() << "footstomp :"  << timer.elapsed() << "/300";
        timer.restart();
    }
    if (m_sc->getDefaultSCI()->isRaised_fingertap())
    {
    	static QElapsedTimer timer;
    	if (timer.isValid())
    		qDebug() << "fingertap :"  << timer.elapsed() << "/ 215";
        timer.restart();
    }

    if (m_sc->getDefaultSCI()->isRaised_done())
    {
        qDebug() << "done";
        QCoreApplication::quit();
    }
}
开发者ID:aboseley,项目名称:YakinduQTimer,代码行数:33,代码来源:DefaultStateChartDriver.cpp

示例3: qHashBench

void qHashBench() {
    QElapsedTimer timer;
    timer.start();
    QHash<int,triple> data;
    triple point;
    int i;

    for (i = 0; i < RAND_COUNT; ++i) {
        point.x = i;
        point.y = rand();
        point.z = rand();
        //printf("%d %d %d %d\n", i, point.x, point.y, point.z);
        data[i] = point;
    }
    qDebug() << Q_FUNC_INFO << "creation: elapsed" << timer.elapsed();
    timer.restart();
    foreach (const triple &t, data) {
        if (t.x % 1000 == 0)
            doSomething(t.x);
    }
    qDebug() << "   foreach: elapsed" << timer.elapsed();
#if QT_VERSION >= 0x050700
    timer.restart();
    foreach (const triple &t, qAsConst(data)) {
        if (t.x % 1000 == 0)
            doSomething(t.x);
    }
    qDebug() << "   qAsConst foreach: elapsed" << timer.elapsed();
#endif
    timer.restart();
    for( auto it = data.begin(); it != data.end(); ++it ) {
        if (it->x % 1000 == 0)
            doSomething(it->x);
    }
    qDebug() << "   range-based for: elapsed" << timer.elapsed();
#if QT_VERSION >= 0x050700
    timer.restart();
    for( auto it = qAsConst(data).begin(); it != qAsConst(data).end(); ++it ) {
        if (it->x % 1000 == 0)
            doSomething(it->x);
    }
    qDebug() << "   qAsConst range-based for: elapsed" << timer.elapsed();
#endif
    timer.restart();
    for (i = 0; i < RAND_COUNT; ++i) {
        auto it = data.find(i);
        Q_ASSERT(it.value().x == i);
        if (it->x % 1000 == 0)
            doSomething(it.value().x);
    }
    qDebug() << "   find: elapsed" << timer.elapsed();
}
开发者ID:ec1oud,项目名称:map-benchmark,代码行数:52,代码来源:main.cpp

示例4: startCopyFile

void MainWindow::startCopyFile(QString &path)
{
    if(isPathExcept(path))
        return;
    // 流逝时间计算
    static QElapsedTimer et;
    et.start();
    lastSynFileNotify("正在同步: " + path);

    if(!autoSyn && !click)
        return;

    for(auto compareFolder : compareList)
    {
        QFileInfo file(path);
        QDir target(compareFolder);
        QString newName = target.filePath(file.fileName());    // 获得文件名,构造路径
        qDebug() << "newPath: " + newName;
        // 同步两个文件
        synTwoFiles(path,newName);

        if(et.elapsed() > 300)
        {
            QCoreApplication::processEvents();
            et.restart();
        }
        lastSynTimeNotify();
    }


}
开发者ID:hellogdut,项目名称:FileSynTool,代码行数:31,代码来源:mainwindow.cpp

示例5: startCapture

void CameraOpenCV::startCapture()
{
    m_videoCap.open(m_devNum);
    std::cout << "Exposure: " << m_videoCap.get(CV_CAP_PROP_EXPOSURE) << std::endl;
    m_videoCap.set(CV_CAP_PROP_EXPOSURE, 10);
    std::cout << "Exposure: " << m_videoCap.get(CV_CAP_PROP_EXPOSURE) << std::endl;

    capturing = m_videoCap.isOpened();

    if (capturing)
    {
        cv::Mat frame, out;
        m_videoCap >> frame;
        QElapsedTimer timer;
        timer.start();
        m_grabTimeMS = 0;
        for (int i = 0; i < 30; ++i)
        {
            m_videoCap >> frame;
            m_grabTimeMS += timer.restart();
        }
        m_grabTimeMS /= 30;
        cout << "Measured grab time: " << m_grabTimeMS << endl;
        cv::cvtColor(frame, out, cv::COLOR_BGR2GRAY);
        m_bytes = out.step * out.rows;
    }
}
开发者ID:gBaltar,项目名称:slstudio,代码行数:27,代码来源:CameraOpenCV.cpp

示例6: main

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QApplication> app(createApplication(argc, argv));



    cv::Mat img, img2, out, out2;
    img = cvLoadImage("Imagenes/city_night.jpeg");
    img2 = cvLoadImage("Imagenes/city_night.jpeg");
    out.create(img.size(), img.type());
    out2.create(img2.size(), img2.type());

    QElapsedTimer timer;
    qint64 nanoSec, nanoSec2;
    timer.start();

    //Lo hace todo en un solo hilo
    cv::threshold(img2,out2,66,255,1);
    nanoSec = timer.nsecsElapsed();
    qDebug() << nanoSec;

    timer.restart();

    // create 8 threads and use TBB
    cv::parallel_for_(cv::Range(0, 8), Parallel_process(img, out, 5, 8));

    nanoSec2 = timer.nsecsElapsed();
    qDebug() << nanoSec - nanoSec2;

    cv::imshow("image", out2);
    cv::imshow("blur", out);

    return app->exec();
}
开发者ID:fabianz66,项目名称:efectos-mondrian-pollock,代码行数:34,代码来源:main.cpp

示例7: process

void TrendDataCollector::process()
{
    qDebug() << "Starting processing...";
    this->setAttribute(this->mAttributeName);

    QMutexLocker ml(&this->mMutex);
    this->mStopProcess = false;
    QElapsedTimer timer;
    timer.start();
    this->updateCurve();
    while (this->mStopProcess == false)
    {
        ml.relock();
        if (this->mPauseProcess == false)
        {
            if (timer.hasExpired(this->mInterval))
            {
                ml.unlock();
                timer.restart();
                this->updateCurve();
            }
        }
        ml.unlock();
        QThread::msleep(10);

    }
    emit finished();
}
开发者ID:filiplindau,项目名称:TrendTest,代码行数:28,代码来源:trenddatacollector.cpp

示例8: gitProgressCB

extern "C" int gitProgressCB(bool reset, const char *text)
{
	static QElapsedTimer timer;
	static qint64 lastTime;
	static QString lastText;
	static QMLManager *self;
	static int lastPercent;

	if (!self)
		self = QMLManager::instance();

	if (!timer.isValid() || reset) {
		timer.restart();
		lastTime = 0;
		lastPercent = 0;
		lastText.clear();
	}
	if (self) {
		qint64 elapsed = timer.elapsed();
		// don't show the same status twice in 200ms
		if (lastText == text && elapsed - lastTime < 200)
			return 0;
		self->loadDiveProgress(++lastPercent);
		QString logText = QString::number(elapsed / 1000.0, 'f', 1) + " / " + QString::number((elapsed - lastTime) / 1000.0, 'f', 3) +
				  QString(" : git %1 (%2)").arg(lastPercent).arg(text);
		self->appendTextToLog(logText);
		qDebug() << logText;
		if (elapsed - lastTime > 500)
			qApp->processEvents();
		lastTime = elapsed;
	}
	// return 0 so that we don't end the download
	return 0;
}
开发者ID:rainzhangtime,项目名称:subsurface,代码行数:34,代码来源:qmlmanager.cpp

示例9: waitForTotalSuccessCount

bool TestLocalSocket_Peer::waitForTotalSuccessCount(quint64 numSuccess, int stepTimeout)
{
	QReadLocker		locker(&m_recLock);
	
	if(!m_recFailureMessages.isEmpty())
		return false;
	
	if(m_recSuccessCount >= numSuccess)
		return true;
	
	QElapsedTimer	timer;
	timer.start();
	while(m_recSuccessCount < numSuccess)
	{
		QCoreApplication::processEvents();
		// Return if we did not receive data or if we received an failure
		timer.restart();
		
		quint64	old	=	m_recSuccessCount;
		if(!m_recValuesChanged.wait(&m_recLock, stepTimeout) || !m_recFailureMessages.isEmpty())
		{
			if(old == m_recSuccessCount)
			{
				if(timer.elapsed() >= stepTimeout)
					break;
				else
					QCoreApplication::processEvents();
			}
		}
	}
	
	return (!m_recFailureMessages.isEmpty() && m_recSuccessCount >= numSuccess);
}
开发者ID:HardcorEViruS,项目名称:MessageBus,代码行数:33,代码来源:testlocalsocket_peer.cpp

示例10: changeImage

void TestQgsSvgCache::changeImage()
{
  bool inCache;
  QgsSvgCache cache;
  // no minimum time between checks
  cache.mFileModifiedCheckTimeout = 0;

  //copy an image to the temp folder
  QString tempImagePath = QDir::tempPath() + "/svg_cache.svg";

  QString originalImage = TEST_DATA_DIR + QStringLiteral( "/test_symbol_svg.svg" );
  if ( QFileInfo::exists( tempImagePath ) )
    QFile::remove( tempImagePath );
  QFile::copy( originalImage, tempImagePath );

  //render it through the cache
  QImage img = cache.svgAsImage( tempImagePath, 200, QColor( 0, 0, 0 ), QColor( 0, 0, 0 ), 1.0,
                                 1.0, inCache );
  QVERIFY( imageCheck( "svgcache_changed_before", img, 30 ) );

  // wait a second so that modified time is different
  QElapsedTimer t;
  t.start();
  while ( !t.hasExpired( 1000 ) )
  {}

  //replace the image in the temp folder
  QString newImage = TEST_DATA_DIR + QStringLiteral( "/test_symbol_svg2.svg" );
  QFile::remove( tempImagePath );
  QFile::copy( newImage, tempImagePath );

  //re-render it
  img = cache.svgAsImage( tempImagePath, 200, QColor( 0, 0, 0 ), QColor( 0, 0, 0 ), 1.0,
                          1.0, inCache );
  QVERIFY( imageCheck( "svgcache_changed_after", img, 30 ) );

  // repeat, with minimum time between checks
  QgsSvgCache cache2;
  QFile::remove( tempImagePath );
  QFile::copy( originalImage, tempImagePath );
  img = cache2.svgAsImage( tempImagePath, 200, QColor( 0, 0, 0 ), QColor( 0, 0, 0 ), 1.0,
                           1.0, inCache );
  QVERIFY( imageCheck( "svgcache_changed_before", img, 30 ) );

  // wait a second so that modified time is different
  t.restart();
  while ( !t.hasExpired( 1000 ) )
  {}

  //replace the image in the temp folder
  QFile::remove( tempImagePath );
  QFile::copy( newImage, tempImagePath );

  //re-render it - not enough time has elapsed between checks, so file modification time will NOT be rechecked and
  // existing cached image should be used
  img = cache2.svgAsImage( tempImagePath, 200, QColor( 0, 0, 0 ), QColor( 0, 0, 0 ), 1.0,
                           1.0, inCache );
  QVERIFY( imageCheck( "svgcache_changed_before", img, 30 ) );
}
开发者ID:CS-SI,项目名称:QGIS,代码行数:59,代码来源:testqgssvgcache.cpp

示例11: preview

void qAnimationDlg::preview()
{
	//we'll take the rendering time into account!
	QElapsedTimer timer;
	timer.start();

	setEnabled(false);

	//reset the interpolators and count the total number of frames
	int frameCount = countFrameAndResetInterpolators();

	//show progress dialog
	QProgressDialog progressDialog(QString("Frames: %1").arg(frameCount), "Cancel", 0, frameCount, this);
	progressDialog.setWindowTitle("Preview");
	progressDialog.show();
	QApplication::processEvents();

	double fps = fpsSpinBox->value();
	
	int frameIndex = 0;
	for ( size_t i=0; i<m_videoSteps.size(); ++i )
	{
		VideoStepItem& currentVideoStep = m_videoSteps[i];

		//theoretical waiting time per frame
		qint64 delay_ms = static_cast<int>(1000 * currentVideoStep.duration_sec / fps);

		cc2DViewportObject currentParams;
		while ( currentVideoStep.interpolator.nextView( currentParams ) )
		{
			timer.restart();
			applyViewport ( &currentParams );
			qint64 dt_ms = timer.elapsed();

			progressDialog.setValue(++frameIndex);
			QApplication::processEvents();
			if (progressDialog.wasCanceled())
			{
				break;
			}

			//remaining time
			if (dt_ms < delay_ms)
			{
				int wait_ms = static_cast<int>(delay_ms - dt_ms);
#if defined(CC_WINDOWS)
				::Sleep( wait_ms );
#else
				usleep( wait_ms * 1000 );
#endif
			}
		}
	}

	//reset view
	onCurrentStepChanged( getCurrentStepIndex() );

	setEnabled(true);
}
开发者ID:vellano,项目名称:CloudCompare,代码行数:59,代码来源:qAnimationDlg.cpp

示例12: timerEvent

 void timerEvent(QTimerEvent *ev) override {
    if (ev->timerId() == timer.timerId() && painter) {
       qreal const t = el.restart() / (qreal)10;
       for (auto &s : state)
          s.advance(t, dst.rect());
       update();
    }
 }
开发者ID:KubaO,项目名称:gripho.it,代码行数:8,代码来源:sbuffer.cpp

示例13: on_action_open_triggered

void MainWindow::on_action_open_triggered()
{
    QString xlsFile = QFileDialog::getOpenFileName(this,QString(),QString(),"excel(*.xls *.xlsx)");
    if(xlsFile.isEmpty())
        return;
    QElapsedTimer timer;
    timer.start();
    if(m_xls.isNull())
        m_xls.reset(new ExcelBase);
    m_xls->open(xlsFile);
    qDebug()<<"open cost:"<<timer.elapsed()<<"ms";timer.restart();
    m_xls->setCurrentSheet(1);
    m_xls->readAll(m_datas);
    qDebug()<<"read data cost:"<<timer.elapsed()<<"ms";timer.restart();
    QVariantListListModel* md = qobject_cast<QVariantListListModel*>(ui->tableView->model());
    if(md)
    {
        md->updateData();
    }
    qDebug()<<"show data cost:"<<timer.elapsed()<<"ms";timer.restart();
}
开发者ID:KoN-Fantazia,项目名称:czyBlog,代码行数:21,代码来源:MainWindow.cpp

示例14: writeSnapshots

void IndexBuilder::writeSnapshots(Reader &reader, KZip &zip)
{
	static const qint64 SNAPSHOT_INTERVAL_MS = 1000; // snapshot interval in milliseconds
	static const int SNAPSHOT_MIN_ACTIONS = 200; // minimum number of actions between snapshots

	paintcore::LayerStack image;
	net::LayerListModel layermodel;
	canvas::StateTracker statetracker(&image, &layermodel, 1);

	MessageRecord msg;
	int snapshotCounter = 0;
	QElapsedTimer timer;
	timer.start();
	while(true) {
		if(_abortflag.load())
			return;

		msg = reader.readNext();
		if(msg.status == MessageRecord::END_OF_RECORDING)
			break;
		else if(msg.status == MessageRecord::INVALID)
			continue;

		protocol::MessagePtr m(msg.message);
		if(m->isCommand()) {
			statetracker.receiveCommand(m);
			++snapshotCounter;
		}

		// Save a snapshot every SNAPSHOT_INTERVAL or at every marker. (But no more often than SNAPSHOT_MIN_ACTIONS)
		// Note. We use the actual elapsed rendering time to decide when to snapshot. This means that (ideally),
		// the time it takes to jump to a snapshot is at most SNAPSHOT_INTERVAL milliseconds (+ the time it takes to load the snapshot)
		if(m_index.snapshots().isEmpty() || ((timer.hasExpired(SNAPSHOT_INTERVAL_MS) || m->type() == protocol::MSG_MARKER) && snapshotCounter>=SNAPSHOT_MIN_ACTIONS)) {
			qint64 streampos = reader.filePosition();
			emit progress(streampos);
			canvas::StateSavepoint sp = statetracker.createSavepoint(-1);

			QBuffer buf;
			buf.open(QBuffer::ReadWrite);
			{
				QDataStream ds(&buf);
				sp.toDatastream(ds);
			}

			int snapshotIdx = m_index.m_snapshots.size();
			zip.writeFile(QString("snapshot-%1").arg(snapshotIdx), buf.data());
			m_index.m_snapshots.append(SnapshotEntry(streampos, reader.currentIndex()));

			snapshotCounter = 0;
			timer.restart();
		}
	}
}
开发者ID:LionsPhil,项目名称:Drawpile,代码行数:53,代码来源:indexbuilder.cpp

示例15: finalizeHeadersWrite

bool CWsgiEngine::finalizeHeadersWrite(Context *c, quint16 status, const Headers &headers, void *engineData)
{
    auto conn = static_cast<QIODevice*>(engineData);

    conn->write("HTTP/1.1 ", 9);
    int msgLen;
    const char *msg = httpStatusMessage(status, &msgLen);
    conn->write(msg, msgLen);

    auto sock = qobject_cast<TcpSocket*>(conn);
    const auto headersData = headers.data();
    if (sock->headerClose == 1) {
        sock->headerClose = 0;
    }

    bool hasDate = false;
    auto it = headersData.constBegin();
    const auto endIt = headersData.constEnd();
    while (it != endIt) {
        const QString key = it.key();
        const QString value = it.value();
        if (sock->headerClose == 0 && key == QLatin1String("connection")) {
            if (value.compare(QLatin1String("close"), Qt::CaseInsensitive) == 0) {
                sock->headerClose = 2;
            } else {
                sock->headerClose = 1;
            }
        } else if (!hasDate && key == QLatin1String("date")) {
            hasDate = true;
        }

        QString ret(QLatin1String("\r\n") + camelCaseHeader(key) + QLatin1String(": ") + value);
        conn->write(ret.toLatin1());

        ++it;
    }

    if (!hasDate) {
        static QByteArray lastDate = dateHeader();
        static QElapsedTimer timer = timerSetup();
        if (timer.hasExpired(1000)) {
            lastDate = dateHeader();
            timer.restart();
        }
        conn->write(lastDate);
    }

    static QByteArray server = serverHeader();
    conn->write(server);

    return conn->write("\r\n\r\n", 4) == 4;
}
开发者ID:buschmann23,项目名称:cutelyst,代码行数:52,代码来源:cwsgiengine.cpp


注:本文中的QElapsedTimer::restart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。