本文整理汇总了C++中QElapsedTimer::hasExpired方法的典型用法代码示例。如果您正苦于以下问题:C++ QElapsedTimer::hasExpired方法的具体用法?C++ QElapsedTimer::hasExpired怎么用?C++ QElapsedTimer::hasExpired使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QElapsedTimer
的用法示例。
在下文中一共展示了QElapsedTimer::hasExpired方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 ) );
}
示例2: 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();
}
示例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: executeOperationsForTime
//![2]
void executeOperationsForTime(int ms)
{
QElapsedTimer timer;
timer.start();
while (!timer.hasExpired(ms))
slowOperation1();
}
示例5: simultaneousWaitOnChildren
void AssignmentClientMonitor::simultaneousWaitOnChildren(int waitMsecs) {
QElapsedTimer waitTimer;
waitTimer.start();
// loop as long as we still have processes around and we're inside the wait window
while(_childProcesses.size() > 0 && !waitTimer.hasExpired(waitMsecs)) {
// continue processing events so we can handle a process finishing up
QCoreApplication::processEvents();
}
}
示例6: 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();
}
}
}
示例7: 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;
}
示例8: downloadProgress
void idupdaterui::downloadProgress( qint64 recvd, qint64 total )
{
static QElapsedTimer timer;
static qint64 lastRecvd = 0;
if( timer.hasExpired( 1000 ) )
{
m_downloadStatus->setText( QString( "%1 KB/s" ).arg( (recvd - lastRecvd) / timer.elapsed() ) );
lastRecvd = recvd;
timer.restart();
}
m_downloadProgress->setMaximum( total );
m_downloadProgress->setValue( recvd );
}
示例9: lock
/*!
Attempts to create the lock file. This function returns \c true if the
lock was obtained; otherwise it returns \c false. If another process (or
another thread) has created the lock file already, this function will
wait for at most \a timeout milliseconds for the lock file to become
available.
Note: Passing a negative number as the \a timeout is equivalent to
calling lock(), i.e. this function will wait forever until the lock
file can be locked if \a timeout is negative.
If the lock was obtained, it must be released with unlock()
before another process (or thread) can successfully lock it.
Calling this function multiple times on the same lock from the same
thread without unlocking first is not allowed, this function will
\e always return false when attempting to lock the file recursively.
\sa lock(), unlock()
*/
bool QLockFile::tryLock(int timeout)
{
Q_D(QLockFile);
QElapsedTimer timer;
if (timeout > 0)
timer.start();
int sleepTime = 100;
forever {
d->lockError = d->tryLock_sys();
switch (d->lockError) {
case NoError:
d->isLocked = true;
return true;
case PermissionError:
case UnknownError:
return false;
case LockFailedError:
if (!d->isLocked && d->isApparentlyStale()) {
// Stale lock from another thread/process
// Ensure two processes don't remove it at the same time
QLockFile rmlock(d->fileName + QLatin1String(".rmlock"));
if (rmlock.tryLock()) {
if (d->isApparentlyStale() && d->removeStaleLock())
continue;
}
}
break;
}
if (timeout == 0 || (timeout > 0 && timer.hasExpired(timeout)))
return false;
QLockFileThread::msleep(sleepTime);
if (sleepTime < 5 * 1000)
sleepTime *= 2;
}
// not reached
return false;
}
示例10: RoutePackets
void CNetwork::RoutePackets()
{
m_bPacketsPending = true;
static quint32 nWhatToRoute = 0;
if(Datagrams.m_pSection.tryLock(50))
{
if(Neighbours.m_pSection.tryLock(50))
{
QElapsedTimer oTimer;
oTimer.start();
switch(nWhatToRoute)
{
case 0:
while(!Datagrams.m_lPendingQH2.isEmpty() && !oTimer.hasExpired(250))
{
QueuedQueryHit pHit = Datagrams.m_lPendingQH2.takeFirst();
if(pHit.m_pInfo->m_oNodeAddress == pHit.m_pInfo->m_oSenderAddress)
{
// hits node address matches sender address
Network.m_oRoutingTable.Add(pHit.m_pInfo->m_oNodeGUID, pHit.m_pInfo->m_oSenderAddress);
}
else if(!pHit.m_pInfo->m_lNeighbouringHubs.isEmpty())
{
// hits address does not match sender address (probably forwarded by a hub)
// and there are neighbouring hubs available, use them instead (sender address can be used instead...)
Network.m_oRoutingTable.Add(pHit.m_pInfo->m_oNodeGUID, pHit.m_pInfo->m_lNeighbouringHubs[0], false);
}
RoutePacket(pHit.m_pInfo->m_oGUID, pHit.m_pPacket);
pHit.m_pPacket->Release();
delete pHit.m_pInfo;
}
nWhatToRoute = 1;
break;
case 1:
while(!Datagrams.m_lPendingQA.isEmpty() && !oTimer.hasExpired(250))
{
QPair<QUuid, G2Packet*> oPair = Datagrams.m_lPendingQA.takeFirst();
RoutePacket(oPair.first, oPair.second);
oPair.second->Release();
}
while(!Datagrams.m_lPendingQKA.isEmpty() && !oTimer.hasExpired(250))
{
QPair<QHostAddress, G2Packet*> oPair = Datagrams.m_lPendingQKA.takeFirst();
if(CNeighbour* pNode = Neighbours.Find(oPair.first, dpGnutella2))
{
((CG2Node*)pNode)->SendPacket(oPair.second, true, true);
}
else
{
oPair.second->Release();
}
}
nWhatToRoute = 0;
break;
}
m_bPacketsPending = (!Datagrams.m_lPendingQA.isEmpty() || !Datagrams.m_lPendingQH2.isEmpty() || !Datagrams.m_lPendingQKA.isEmpty());
Neighbours.m_pSection.unlock();
}
systemLog.postLog(LogSeverity::Debug, QString("Datagrams left to be routed: QA:%1 QH2:%2 QKA:%3").arg(Datagrams.m_lPendingQA.size()).arg(Datagrams.m_lPendingQH2.size()).arg(Datagrams.m_lPendingQKA.size()));
//qDebug() << "Datagrams left to be routed: QA:" << Datagrams.m_lPendingQA.size() << " QH2:" << Datagrams.m_lPendingQH2.size() << " QKA:" << Datagrams.m_lPendingQKA.size();
Datagrams.m_pSection.unlock();
}
}
示例11: runTest
void FuzzyTester::runTest(const QString &profile, const QString &startCommit,
int maxDurationInMinutes, int jobCount, bool log)
{
m_profile = profile;
m_jobCount = jobCount;
m_log = log;
runGit(QStringList() << "rev-parse" << "HEAD", &m_headCommit);
qDebug("HEAD is %s", qPrintable(m_headCommit));
qDebug("Trying to find a buildable commit to start with...");
const QString workingStartCommit = findWorkingStartCommit(startCommit);
qDebug("Found buildable start commit %s.", qPrintable(workingStartCommit));
QStringList allCommits = findAllCommits(workingStartCommit);
qDebug("The test set comprises all %d commits between the start commit and HEAD.",
allCommits.size());
// Shuffle the initial sequence. Otherwise all invocations of the tool with the same start
// commit would try the same sequence of commits.
std::srand(std::time(nullptr));
std::random_shuffle(allCommits.begin(), allCommits.end());
quint64 run = 0;
QStringList buildSequence(workingStartCommit);
QElapsedTimer timer;
const qint64 maxDurationInMillis = maxDurationInMinutes * 60 * 1000;
if (maxDurationInMillis != 0)
timer.start();
bool timerHasExpired = false;
while (std::next_permutation(allCommits.begin(), allCommits.end()) && !timerHasExpired) {
qDebug("Testing permutation %llu...", ++run);
const auto &allCommitsImmutable = allCommits;
for (const QString ¤tCommit : allCommitsImmutable) {
if (timer.isValid() && timer.hasExpired(maxDurationInMillis)) {
timerHasExpired = true;
break;
}
m_currentCommit = currentCommit;
buildSequence << currentCommit;
checkoutCommit(currentCommit);
qDebug("Testing incremental build #%d (%s)", buildSequence.size() - 1,
qPrintable(currentCommit));
// Doing "resolve" and "build" separately introduces additional possibilities
// for errors, as information from change tracking has to be serialized correctly.
QString qbsError;
m_currentActivity = resolveIncrementalActivity();
bool success = runQbs(defaultBuildDir(), QLatin1String("resolve"), &qbsError);
if (success) {
m_currentActivity = buildIncrementalActivity();
success = runQbs(defaultBuildDir(), QLatin1String("build"), &qbsError);
}
m_currentActivity = buildFromScratchActivity();
if (success) {
if (!doCleanBuild(&qbsError)) {
QString message = "An incremental build succeeded "
"with a commit for which a clean build failed.";
if (!m_log) {
message += QString::fromLatin1("\nThe qbs error message "
"for the clean build was: '%1'").arg(qbsError);
}
throwIncrementalBuildError(message, buildSequence);
}
} else {
qDebug("Incremental build failed. Checking whether clean build works...");
if (doCleanBuild()) {
QString message = "An incremental build failed "
"with a commit for which a clean build succeeded.";
if (!m_log) {
message += QString::fromLatin1("\nThe qbs error message for "
"the incremental build was: '%1'").arg(qbsError);
}
throwIncrementalBuildError(message, buildSequence);
} else {
qDebug("Clean build also fails. Continuing.");
}
}
}
}
if (timerHasExpired)
qDebug("Maximum duration reached.");
else
qDebug("All possible permutations were tried.");
}