本文整理汇总了C++中QDateTime::msecsTo方法的典型用法代码示例。如果您正苦于以下问题:C++ QDateTime::msecsTo方法的具体用法?C++ QDateTime::msecsTo怎么用?C++ QDateTime::msecsTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDateTime
的用法示例。
在下文中一共展示了QDateTime::msecsTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNextTrigger
qint64 TTiming::getNextTrigger(QDateTime actual)
{
qint64 ret = 0;
QDateTime calculate = wall_clock.datetime;
if (actual > wall_clock.datetime)
{
// if wallclock date is in past and repeats -1 (indefinite) get time for the next event/trigger/shot from period
if (wall_clock.repeats == -1)
{
// find out the next possible trigger based on the datetime of the wallclock
do
{
calculate = addWallClockIntervalOptimized(actual, calculate); // do some shortcuts cause addWallClockInterval is extremly slow on long times
}
while (actual > calculate);
ret = actual.msecsTo(calculate);
}
// if wallclock date is in past and repeats > 0 calculate elapsed time since init and look if there is be another event possible
else if (wall_clock.repeats > 0)
ret = analyseRemainingRepeats(actual);
// repeat 0 return 0 ms
}
else // datetime of wallclock is in future
ret = actual.msecsTo(wall_clock.datetime);
return ret;
}
示例2: updateStatusDescription
void WalletStatusBar::updateStatusDescription() {
if (!m_walletIsSynchronized) {
return;
}
quint32 localBlockCount = m_nodeStateModel->index(0, NodeStateModel::COLUMN_LOCAL_BLOCK_COUNT).data(NodeStateModel::ROLE_LOCAL_BLOCK_COUNT).value<quint32>();
QDateTime lastLocalBlockTimestamp = QDateTime::fromTime_t(m_nodeStateModel->index(0, NodeStateModel::COLUMN_LAST_LOCAL_BLOCK_TIMESTAMP).data(NodeStateModel::ROLE_LAST_LOCAL_BLOCK_TIMESTAMP).value<quint64>()).toUTC();
quintptr peerCount = m_nodeStateModel->index(0, NodeStateModel::COLUMN_PEER_COUNT).data(NodeStateModel::ROLE_PEER_COUNT).value<quintptr>();
QDateTime currentDateTime = QDateTime::currentDateTimeUtc();
quint64 timeDiff = lastLocalBlockTimestamp.msecsTo(currentDateTime);
QString warningString;
if (timeDiff > MSECS_IN_HOUR) {
warningString.append(QString(" Warning: last block was received %1 hours %2 minutes ago.").
arg(timeDiff / MSECS_IN_HOUR).arg((timeDiff % MSECS_IN_HOUR) / MSECS_IN_MINUTE));
}
if (peerCount == 0) {
warningString.append(tr(" No network connection."));
}
QString statusText = tr("Wallet synchronized. Top block height: %1 / Time (UTC): %2%3");
m_syncStatusLabel->setText(statusText.arg(localBlockCount - 1).
arg(QLocale(QLocale::English).toString(lastLocalBlockTimestamp, "dd MMM yyyy, HH:mm:ss")).
arg(warningString));
}
示例3: writeLog
void Logger::writeLog(quint32 AType, const QString &AClass, const QString &AMessage)
{
QMutexLocker locker(&FMutex);
LoggerData *q = instance()->d;
if ((q->enabledTypes & AType)>0 && q->logFile.isOpen())
{
static QDateTime lastLogTime = QDateTime::currentDateTime();
QDateTime curDateTime = QDateTime::currentDateTime();
QString typeName;
switch(AType)
{
case Logger::Fatal:
typeName = "!FTL";
break;
case Logger::Error:
typeName = "!ERR";
break;
case Logger::Warning:
typeName = "*WNG";
break;
case Logger::Info:
typeName = " INF";
break;
case Logger::View:
typeName = " VIW";
break;
case Logger::Event:
typeName = " EVT";
break;
case Logger::Timing:
typeName = " TMG";
break;
case Logger::Debug:
typeName = " DBG";
break;
case Logger::Stanza:
typeName = " STZ";
break;
default:
typeName = QString(" T%1").arg(AType);
}
QString timestamp = curDateTime.toString("hh:mm:ss.zzz");
int timeDelta = lastLogTime.msecsTo(curDateTime);
QString logLine = QString("%1\t+%2\t%3\t[%4] %5").arg(timestamp).arg(timeDelta).arg(typeName,AClass,AMessage);
q->logFile.write(logLine.toUtf8());
q->logFile.write("\r\n");
q->logFile.flush();
#if defined(DEBUG_MODE)
if (AType <= Logger::Warning)
qDebug() << logLine;
#endif
q->loggedTypes |= AType;
lastLogTime = curDateTime;
}
}
示例4: qDebug
void
RuleWatch::refreshWatch(const QDateTime &now) {
qDebug("RuleWatch::refreshWatch(%s)", qPrintable(now.toString()));
_timer.stop();
QDateTime nextNearestDateTime;
qDebug("RuleWatch::refreshWatch size of rules: %d", _rules->size());
for (Rules::const_iterator i = _rules->constBegin(); i != _rules->constEnd(); ++i) {
const RuleItem &item = *i;
if (item.ruleActive) {
QDateTime nearestFromRule = _nextDateTimeFromRule(now, item);
if (!nearestFromRule.isNull() && (nextNearestDateTime.isNull() || nearestFromRule < nextNearestDateTime)) {
qDebug("Setting nearest to %s, was %s",
qPrintable(nearestFromRule.toString()),
qPrintable(nextNearestDateTime.toString()));
nextNearestDateTime = nearestFromRule;
_targetRuleItem = &item;
}
}
}
if (!nextNearestDateTime.isNull()) {
quint64 interval = now.msecsTo(nextNearestDateTime);
qDebug("Now %s", qPrintable(now.toString()));
qDebug("Scheduling a timer to %s, interval %dms", qPrintable(nextNearestDateTime.toString()), (int)interval);
_timer.start(interval);
} else {
_targetRuleItem = NULL;
qDebug("No nearest time based rule found");
}
}
示例5: timeUntilTomorrow
qint64 timeUntilTomorrow()
{
QDateTime now = QDateTime::currentDateTime();
QDateTime tomorrow = now.addDays(1); // Tomorrow.
tomorrow.setTime(QTime()); // Midnight.
return now.msecsTo(tomorrow);
}
示例6: timerEvent
void MainWindow::timerEvent(QTimerEvent *)
{
if(mRunning)
{
mSessionTime = mStartTime.msecsTo(QDateTime::currentDateTime());
qint64 time = mTotalTime + mSessionTime;
time *= 111;
ui->mLabel->setText(CalculateTimeStr(time));
}
}
示例7: updateFile
void FileTransferWindow::updateFile(qlonglong position, qlonglong total)
{
static QDateTime lastUpdate = QDateTime::currentDateTime();
if (lastUpdate.msecsTo(QDateTime::currentDateTime()) < 200)
return;
lastUpdate = QDateTime::currentDateTime();
double progress = (100.0 * position) / double(total);
ui.progressBar->setValue(static_cast<int>(progress));
}
示例8: iterate
bool TestOperation::iterate()
{
QDateTime start = QDateTime::currentDateTime();
QDateTime stepStart = QDateTime::currentDateTime();
if (!this->computeVectors()) {
return false;
}
qDebug() << "Compute time (s):"
<< stepStart.secsTo(QDateTime::currentDateTime());
stepStart = QDateTime::currentDateTime();
if (!this->applyVectors()) {
return false;
}
qDebug() << "Apply time (s):"
<< stepStart.secsTo(QDateTime::currentDateTime());
stepStart = QDateTime::currentDateTime();
if (!this->savePixmap()) {
return false;
}
qDebug() << "Pixmap time (ms):"
<< stepStart.msecsTo(QDateTime::currentDateTime());
stepStart = QDateTime::currentDateTime();
if (!this->advanceSeeds()) {
return false;
}
qDebug() << "Advance time (ms):"
<< stepStart.msecsTo(QDateTime::currentDateTime());
qDebug() << "Frame time (s):"
<< start.secsTo(QDateTime::currentDateTime());
return true;
}
示例9: start
void PropagateUploadFileQNAM::start()
{
if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
return;
_file = new QFile(_propagator->getFilePath(_item._file), this);
if (!_file->open(QIODevice::ReadOnly)) {
done(SyncFileItem::NormalError, _file->errorString());
delete _file;
return;
}
// Update the mtime and size, it might have changed since discovery.
_item._modtime = FileSystem::getModTime(_file->fileName());
quint64 fileSize = _file->size();
_item._size = fileSize;
// But skip the file if the mtime is too close to 'now'!
// That usually indicates a file that is still being changed
// or not yet fully copied to the destination.
QDateTime modtime = Utility::qDateTimeFromTime_t(_item._modtime);
if (modtime.msecsTo(QDateTime::currentDateTime()) < minFileAgeForUpload) {
_propagator->_anotherSyncNeeded = true;
done(SyncFileItem::SoftError, tr("Local file changed during sync."));
delete _file;
return;
}
_chunkCount = std::ceil(fileSize/double(chunkSize()));
_startChunk = 0;
_transferId = qrand() ^ _item._modtime ^ (_item._size << 16);
const SyncJournalDb::UploadInfo progressInfo = _propagator->_journal->getUploadInfo(_item._file);
if (progressInfo._valid && Utility::qDateTimeToTime_t(progressInfo._modtime) == _item._modtime ) {
_startChunk = progressInfo._chunk;
_transferId = progressInfo._transferid;
qDebug() << Q_FUNC_INFO << _item._file << ": Resuming from chunk " << _startChunk;
}
_currentChunk = 0;
_duration.start();
emit progress(_item, 0);
this->startNextChunk();
}
示例10: finishTiming
qint64 Logger::finishTiming(const QString &AVariable, const QString &AContext)
{
qint64 timing = -1;
QMutexLocker locker(&FMutex);
LoggerData *q = instance()->d;
QMap<QString, QDateTime> &varMap = q->timings[AVariable];
QDateTime startTime = varMap.take(AContext);
if (startTime.isValid())
timing = startTime.msecsTo(QDateTime::currentDateTime());
if (varMap.isEmpty())
q->timings.remove(AVariable);
return timing;
}
示例11: readData
void Sensor::readData()
{
SensorReading reading;
while (m_serialPort.canReadLine()) {
QByteArray line = m_serialPort.readLine().trimmed();
if (!reading.fromCsv(line)) {
emit error(reading.lastError());
break;
}
m_readings.append(reading);
QDateTime firstTime = m_readings.first().time();
if (firstTime.msecsTo(QDateTime::currentDateTimeUtc()) >= 5000) {
// We have 5 seconds of readings, so emit the batch.
emit analyze(m_readings);
m_readings.clear();
}
}
}
示例12: analyseRemainingRepeats
qint64 TTiming::analyseRemainingRepeats(QDateTime actual)
{
QDateTime calculate = wall_clock.datetime;
qint64 ret = 0;
int i = 0;
remaining_repeats = 0;
do
{
calculate = addWallClockInterval(calculate);
i++;
}
while (actual > calculate && i < wall_clock.repeats+1);
if (actual < calculate)
{
ret = actual.msecsTo(calculate);
remaining_repeats = wall_clock.repeats - i;
}
return ret;
}
示例13: timerTimeout
void MarbleClockPrivate::timerTimeout()
{
// calculate real period elapsed since last call
QDateTime curenttime( QDateTime::currentDateTimeUtc() );
int msecdelta = m_lasttime.msecsTo( curenttime );
m_lasttime = curenttime;
// update m_datetime at m_speed pace
m_datetime = m_datetime.addMSecs( msecdelta * m_speed );
// trigger round minute update (at m_speed pace)
emit q->timeChanged();
// sleeptime is the time to sleep until next round minute, at m_speed pace
int sleeptime = ( m_updateInterval * 1000 - (qreal)(m_datetime.time().msec() + m_datetime.time().second() * 1000 ) ) / m_speed;
if ( sleeptime < 1000 ) {
// don't trigger more often than 1s
sleeptime = 1000;
}
m_timer.start( sleeptime );
//mDebug() << "MarbleClock: will sleep for " << sleeptime;
}
示例14: isValidTick
// 每次收盘/断网/崩溃/退出等等,都会清空ringbufer,需要重来一下下面的逻辑=
// 1.总成交量为0的:无效=
// 2.确定第一个有效tick:交易日期+时间,和当前时间偏离在3分钟之外:无效=
// 3.确定后续tick是否有效:和上一个tick相比,总成交量不变的:无效=
bool isValidTick(RingBuffer* rb, CThostFtdcDepthMarketDataField* curTick)
{
if (curTick->Volume == 0) {
return false;
}
auto preTick = (CThostFtdcDepthMarketDataField*)rb->get(rb->head());
if (!preTick) {
// ActionDay 指当时的日期
// TradingDay 是指当时的交易日期,夜盘算下一个交易的=
QDateTime curDateTime = QDateTime::currentDateTime();
QString tickDateTimeStr = QString().sprintf("%s %s.%03d", curTick->ActionDay, curTick->UpdateTime, curTick->UpdateMillisec);
QDateTime tickDateTime = QDateTime::fromString(tickDateTimeStr, "yyyyMMdd hh:mm:ss.zzz");
qint64 delta = qAbs(curDateTime.msecsTo(tickDateTime));
if (delta >= 3 * 60 * 1000) {
return false;
}
} else {
if (preTick->Volume == curTick->Volume) {
return false;
}
}
return true;
}
示例15: return
/*
Qt 4.6 does not have the msecsTo function - so we roll our own.
Return the number of milliseconds from this datetime to the other datetime.
If the other datetime is earlier than this datetime, the value returned is negative.
Based on msecsTo out of qt-everywhere-opensource-src-4.8.4/src/corelib/tools/qdatetime.cpp
*/
static qint64 msecsTo_48 (const QDateTime& self, const QDateTime& other)
{
#if (QT_VERSION >= QT_VERSION_CHECK(4, 8, 0))
return self.msecsTo( other );
#else
// More or less a direct copy of 4.8 code.
//
enum { MSECS_PER_DAY = 86400000 };
QDate selfDate;
QDate otherDate;
QTime selfTime;
QTime otherTime;
selfDate = self.toUTC().date();
selfTime = self.toUTC().time();
otherDate = other.toUTC().date();
otherTime = other.toUTC().time();
return (static_cast<qint64>(selfDate.daysTo(otherDate)) * static_cast<qint64>(MSECS_PER_DAY)) +
static_cast<qint64>(selfTime.msecsTo(otherTime));
#endif
}