本文整理汇总了C++中QElapsedTimer::start方法的典型用法代码示例。如果您正苦于以下问题:C++ QElapsedTimer::start方法的具体用法?C++ QElapsedTimer::start怎么用?C++ QElapsedTimer::start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QElapsedTimer
的用法示例。
在下文中一共展示了QElapsedTimer::start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: waitForRead
bool QNativeSocketEngine::waitForRead(int msecs, bool *timedOut)
{
Q_D(QNativeSocketEngine);
Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::waitForRead(), false);
Q_CHECK_NOT_STATE(QNativeSocketEngine::waitForRead(),
QAbstractSocket::UnconnectedState, false);
if (timedOut)
*timedOut = false;
QElapsedTimer timer;
timer.start();
while (msecs > timer.elapsed()) {
// Servers with active connections are ready for reading
if (!d->currentConnections.isEmpty())
return true;
// If we are a client, we are ready to read if our buffer has data
QMutexLocker locker(&d->readMutex);
if (!d->readBytes.atEnd())
return true;
// Nothing to do, wait for more events
d->eventLoop.processEvents();
}
d->setError(QAbstractSocket::SocketTimeoutError,
QNativeSocketEnginePrivate::TimeOutErrorString);
if (timedOut)
*timedOut = true;
return false;
}
示例2: 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;
}
}
示例3: wait
void wait(int ms)
{
Q_ASSERT(ms >= 0);
if (ms == 0) {
return;
}
QElapsedTimer timer;
timer.start();
if (ms <= 50) {
QCoreApplication::processEvents(QEventLoop::AllEvents, ms);
sleep(qMax(ms - static_cast<int>(timer.elapsed()), 0));
}
else {
int timeLeft;
do {
timeLeft = ms - timer.elapsed();
if (timeLeft > 0) {
QCoreApplication::processEvents(QEventLoop::AllEvents, timeLeft);
sleep(10);
}
} while (!timer.hasExpired(ms));
}
}
示例4: mousePressEvent
/*!
\reimp
*/
void QScrollBar::mousePressEvent(QMouseEvent *e)
{
Q_D(QScrollBar);
if (d->repeatActionTimer.isActive())
d->stopRepeatAction();
bool midButtonAbsPos = style()->styleHint(QStyle::SH_ScrollBar_MiddleClickAbsolutePosition,
0, this);
QStyleOptionSlider opt;
initStyleOption(&opt);
if (d->maximum == d->minimum // no range
|| (e->buttons() & (~e->button())) // another button was clicked before
|| !(e->button() == Qt::LeftButton || (midButtonAbsPos && e->button() == Qt::MidButton)))
return;
d->pressedControl = style()->hitTestComplexControl(QStyle::CC_ScrollBar, &opt, e->pos(), this);
d->pointerOutsidePressedControl = false;
QRect sr = style()->subControlRect(QStyle::CC_ScrollBar, &opt,
QStyle::SC_ScrollBarSlider, this);
QPoint click = e->pos();
QPoint pressValue = click - sr.center() + sr.topLeft();
d->pressValue = d->orientation == Qt::Horizontal ? d->pixelPosToRangeValue(pressValue.x()) :
d->pixelPosToRangeValue(pressValue.y());
if (d->pressedControl == QStyle::SC_ScrollBarSlider) {
d->clickOffset = HORIZONTAL ? (click.x()-sr.x()) : (click.y()-sr.y());
d->snapBackPosition = d->position;
}
if ((d->pressedControl == QStyle::SC_ScrollBarAddPage
|| d->pressedControl == QStyle::SC_ScrollBarSubPage)
&& ((midButtonAbsPos && e->button() == Qt::MidButton)
|| (style()->styleHint(QStyle::SH_ScrollBar_LeftClickAbsolutePosition, &opt, this)
&& e->button() == Qt::LeftButton))) {
int sliderLength = HORIZONTAL ? sr.width() : sr.height();
setSliderPosition(d->pixelPosToRangeValue((HORIZONTAL ? e->pos().x()
: e->pos().y()) - sliderLength / 2));
d->pressedControl = QStyle::SC_ScrollBarSlider;
d->clickOffset = sliderLength / 2;
}
const int initialDelay = 500; // default threshold
QElapsedTimer time;
time.start();
d->activateControl(d->pressedControl, initialDelay);
repaint(style()->subControlRect(QStyle::CC_ScrollBar, &opt, d->pressedControl, this));
if (time.elapsed() >= initialDelay && d->repeatActionTimer.isActive()) {
// It took more than 500ms (the initial timer delay) to process
// the control activation and repaint(), we therefore need
// to restart the timer in case we have a pending mouse release event;
// otherwise we'll get a timer event right before the release event,
// causing the repeat action to be invoked twice on a single mouse click.
// 50ms is the default repeat time (see activateControl/setRepeatAction).
d->repeatActionTimer.start(50, this);
}
if (d->pressedControl == QStyle::SC_ScrollBarSlider)
setSliderDown(true);
}
示例5: 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 ) );
}
示例6: 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 ( ¤tParams );
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);
}
示例7: run
void BleWindowsCaptureSource::run()
{
// TODO make could select screen
// QGuiApplication::screens();
while (!m_stop) {
QElapsedTimer elapsedTimer;
elapsedTimer.start();
QScreen *screen = QGuiApplication::primaryScreen();
if (screen) {
QPixmap pixmap = screen->grabWindow(m_wid, m_x, m_y, m_width, m_height);
#if 1
// TODO to draw cursor to image
QRect desktopRect = QRect(QPoint(0, 0), screen->size());
if (desktopRect.contains(QCursor::pos())) {
drawCursor(&pixmap);
}
#endif
QImage image = pixmap.toImage();
m_modifyMutex.lock(); // Start lock
BleImage be;
be.width = image.width();
be.height = image.height();
int imageSize = be.width * be.height * 3;
be.data = new char[imageSize];
IplImage *oriImage = cvCreateImageHeader(cvSize(image.width(), image.height()), IPL_DEPTH_8U, 4);
cvSetData(oriImage, image.bits(), image.bytesPerLine());
IplImage *dstImage = cvCreateImageHeader(cvSize(image.width(), image.height()), IPL_DEPTH_8U, 3);
cvSetData(dstImage, be.data, be.width * 3);
cvCvtColor(oriImage, dstImage, CV_BGRA2BGR);
be.dataSize = imageSize;
be.format = BleImage_Format_BGR24;
m_image = be;
cvReleaseImageHeader(&oriImage);
cvReleaseImageHeader(&dstImage);
m_modifyMutex.unlock(); // End unlock
}
int elapsedMs = elapsedTimer.elapsed();
int needSleepMs = m_interval - elapsedMs;
if (needSleepMs < 0) {
needSleepMs = 0;
}
msleep(needSleepMs);
}
log_trace("BleWindowsCaptureSource exit normally.");
}
示例8: delay
void delay(unsigned int msecs)
{
QElapsedTimer t;
t.start();
while ( t.elapsed() < msecs )
{}
//QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
示例9: statics
void tst_QElapsedTimer::statics()
{
qDebug() << "Clock type is" << QElapsedTimer::clockType();
qDebug() << "Said clock is" << (QElapsedTimer::isMonotonic() ? "monotonic" : "not monotonic");
QElapsedTimer t;
t.start();
qDebug() << "Current time is" << t.msecsSinceReference();
}
示例10: toggleRunning
void toggleRunning() {
if (timer.isActive())
timer.stop();
else {
timer.start(10, this);
el.start();
}
}
示例11: executeOperationsForTime
//![2]
void executeOperationsForTime(int ms)
{
QElapsedTimer timer;
timer.start();
while (!timer.hasExpired(ms))
slowOperation1();
}
示例12: monotonicallyIncreasingTime
double monotonicallyIncreasingTime()
{
ASSERT(QElapsedTimer::isMonotonic());
static QElapsedTimer timer;
if (!timer.isValid())
timer.start();
return timer.nsecsElapsed() / 1.0e9;
}
示例13: waitTaskInfo
void Execut_window::waitTaskInfo(int tim)//延时ms
{
QElapsedTimer t;
t.start();
while(t.elapsed()<tim)
{
QCoreApplication::processEvents();
}
}
示例14: waitTaskInfo
void waitTaskInfo()
{
QElapsedTimer t;
t.start();
while(t.elapsed()<300)
{
QCoreApplication::processEvents();
}
}
示例15: while
void PN532::sleep(quint16 msec)
{
QElapsedTimer t;
t.start();
while(t.elapsed() < msec)
{
QCoreApplication::processEvents();
}
}