本文整理汇总了C++中QDateTime::addMSecs方法的典型用法代码示例。如果您正苦于以下问题:C++ QDateTime::addMSecs方法的具体用法?C++ QDateTime::addMSecs怎么用?C++ QDateTime::addMSecs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDateTime
的用法示例。
在下文中一共展示了QDateTime::addMSecs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: formatEntry
static HistoryEntry formatEntry(QByteArray url, QByteArray title, qlonglong prdate)
{
QDateTime dateTime = QDateTime::fromTime_t(prdate / 1000000);
dateTime.addMSecs((prdate % 1000000) / 1000);
HistoryEntry entry(url, dateTime, title);
return entry;
}
示例2: setMSecsSinceEpoch
/*
Construct a QCa date time set to the same date/time as an EPICS time stamp
*/
QCaDateTime::QCaDateTime( unsigned long seconds, unsigned long nanoseconds )
{
qint64 mSec;
// First calculate mSecs and remaining nSecs
// Down to the millisecond goes in the Qt base class structure,
// the remaining nanoseconds are saved in this class
//
mSec = nanoseconds / 1000000;
nSec = nanoseconds % 1000000;
#if (QT_VERSION >= QT_VERSION_CHECK(4, 8, 0))
// Calc number of mSecs since the epoc.
// Note, although the EPICS time stamp is in seconds since a base, the method which
// takes seconds since a base time uses a different base, so an offset is added.
//
qint64 mSecsSinceEpoch;
mSecsSinceEpoch = ((qint64) (seconds + EPICSQtEpocOffset)) * 1000 + mSec;
setMSecsSinceEpoch (mSecsSinceEpoch);
#else
// setMSecsSinceEpoch does not exist in older versions.
//
QDateTime temp;
temp.setTime_t( seconds + EPICSQtEpocOffset );
*this = temp.addMSecs (mSec);
#endif
}
示例3:
void CAdBlock::setScte35StartTime(QDateTime firstAdStartTime)
{
if (!m_adConfigs.empty())
{
CAdConfig firstAd = m_adConfigs.front();
startB2bTimer(firstAdStartTime.addMSecs(QTime().msecsTo(firstAd.getTotalDuration())));
}
}
示例4: sampleToDate
QDateTime DataFile::sampleToDate(int sample)
{
int timeOffset = round(sample/getSamplingFrequency()*1000);
QDateTime date = getStartDate();
date = date.addMSecs(timeOffset);
return date;
}
示例5: timeSteps
//--------------------------------------------------------------------------------------------------
/// Get list of time step texts (dates)
//--------------------------------------------------------------------------------------------------
void RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, std::vector<QDateTime>* timeSteps, std::vector<double>* daysSinceSimulationStart)
{
if (!ecl_file) return;
CVF_ASSERT(timeSteps && daysSinceSimulationStart);
timeSteps->clear();
daysSinceSimulationStart->clear();
// Get the number of occurrences of the INTEHEAD keyword
int numINTEHEAD = ecl_file_get_num_named_kw(ecl_file, INTEHEAD_KW);
// Get the number of occurrences of the DOUBHEAD keyword
int numDOUBHEAD = ecl_file_get_num_named_kw(ecl_file, DOUBHEAD_KW);
std::vector<double> dayValues(numINTEHEAD, 0.0); // Init fraction to zero
// Read out fraction of day if number of keywords are identical
if (numINTEHEAD == numDOUBHEAD)
{
for (int i = 0; i < numDOUBHEAD; i++)
{
ecl_kw_type* kwDOUBHEAD = ecl_file_iget_named_kw(ecl_file, DOUBHEAD_KW, i);
if (kwDOUBHEAD)
{
dayValues[i] = ecl_kw_iget_double(kwDOUBHEAD, DOUBHEAD_DAYS_INDEX);
}
}
}
std::set<QDateTime> existingTimesteps;
for (int i = 0; i < numINTEHEAD; i++)
{
ecl_kw_type* kwINTEHEAD = ecl_file_iget_named_kw(ecl_file, INTEHEAD_KW, i);
CVF_ASSERT(kwINTEHEAD);
int day = 0;
int month = 0;
int year = 0;
getDayMonthYear(kwINTEHEAD, &day, &month, &year);
QDateTime reportDateTime = RiaQDateTimeTools::createUtcDateTime(QDate(year, month, day));
CVF_ASSERT(reportDateTime.isValid());
double dayValue = dayValues[i];
double dayFraction = dayValue - cvf::Math::floor(dayValue);
double milliseconds = dayFraction * 24.0 * 60.0 * 60.0 * 1000.0;
reportDateTime = reportDateTime.addMSecs(milliseconds);
if (existingTimesteps.insert(reportDateTime).second)
{
timeSteps->push_back(reportDateTime);
daysSinceSimulationStart->push_back(dayValue);
}
}
}
示例6: TEST
TEST(Time, Verify_46_Hack)
{
qint64 MSecsPerDay = 86400000;
QDateTime epoch = QDateTime::fromString("1970-01-01T00:00:00.000", Qt::ISODate);
epoch.setTimeSpec(Qt::UTC);
Time &time = Time::GetInstance();
time.UseRealTime();
QDateTime now = time.CurrentTime();
QDateTime now_46 = QDateTime::currentDateTime().toUTC();
EXPECT_EQ(now_46.date(), now.date());
EXPECT_TRUE(qAbs(now_46.time().msecsTo(now.time())) < 100);
qint64 msecs = time.MSecsSinceEpoch();
now = QDateTime::currentDateTime().toUTC();
int days_46 = epoch.date().daysTo(now.date());
int msecs_46 = epoch.time().msecsTo(now.time());
qint64 total_msecs_46 = (days_46 * MSecsPerDay) + msecs_46;
EXPECT_TRUE(qAbs(msecs - total_msecs_46) < 100);
time.UseVirtualTime();
now = time.CurrentTime();
now_46 = epoch.addMSecs(time.MSecsSinceEpoch());
EXPECT_EQ(now, now_46);
for(int i = 0; i < 50; i++) {
time.IncrementVirtualClock(Random::GetInstance().GetInt());
now = time.CurrentTime();
now_46 = epoch.addMSecs(time.MSecsSinceEpoch());
EXPECT_EQ(now, now_46);
}
}
示例7: addData
void MapLogPlacemarkData::addData(const GeoObjectID &id, SinglePointDataPtr data)
{
if (!mData.contains(id))
{
QVector<SinglePointDataPtr> newHistory;
newHistory.push_back(data);
mData.insert(id, newHistory);
return;
}
if (data->isCritical())
{
insert(id, data);
}
SinglePointDataPtr mostRecent = mData[id].last();
QDateTime lastTime = mostRecent->time();
QDateTime recently = lastTime.addMSecs(mostRecent->durationMs());
QDateTime now = QDateTime::currentDateTime();
qint64 timespan = recently.daysTo(now) * msecsInDay + recently.time().msecsTo(now.time());
if (*data == *mostRecent)
{ //ignore, but advance duration
//qDebug("Data didn't change");
mostRecent->advanceDurationMs(timespan);
return;
}
if (timespan > mTimeResolution)
{
//qDebug("Data changed and fits in resolution, inserting");
insert(id, data);
}
else
{
//qDebug("Data discarded");
if (mExtraDataBehavior == MapLogPlacemarkData::Ignore)
{ //ignore data completely
return;
}
else
{ //TODO compress data somehow (for now also ignore)
return;
}
}
}
示例8: onLoadHistory
void ChatForm::onLoadHistory()
{
LoadHistoryDialog dlg;
if (dlg.exec())
{
QDateTime fromTime = dlg.getFromDate();
QDateTime toTime = QDateTime::currentDateTime();
if (fromTime > toTime)
return;
if (earliestMessage)
{
if (*earliestMessage < fromTime)
return;
if (*earliestMessage < toTime)
{
toTime = *earliestMessage;
toTime = toTime.addMSecs(-1);
}
}
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->userId, fromTime, toTime);
ToxID storedPrevId;
std::swap(storedPrevId, previousId);
QList<ChatActionPtr> historyMessages;
for (const auto &it : msgs)
{
ChatActionPtr ca = genMessageActionAction(ToxID::fromString(it.sender), it.message, false, it.timestamp.toLocalTime());
historyMessages.append(ca);
}
std::swap(storedPrevId, previousId);
int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value();
if (earliestMessage != nullptr)
*earliestMessage = fromTime;
chatWidget->insertMessagesTop(historyMessages);
savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos;
chatWidget->verticalScrollBar()->setValue(savedSliderPos);
}
}
示例9: datetimeFromNumber
QDateTime datetimeFromNumber(double num, bool is1904)
{
if (!is1904 && num > 60)
num = num - 1;
qint64 msecs = static_cast<qint64>(num * 1000*60*60*24.0 + 0.5);
QDateTime epoch(is1904 ? QDate(1904, 1, 1): QDate(1899, 12, 31), QTime(0,0));
QDateTime dt = epoch.addMSecs(msecs);
#if QT_VERSION >= 0x050200
// Remove one hour to see whether the date is Daylight
QDateTime dt2 = dt.addMSecs(-3600);
if (dt2.isDaylightTime())
return dt2;
#endif
return dt;
}
示例10: 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;
}
示例11: sendNotifications_Reminders
void Calendar::sendNotifications_Reminders()
{
QDateTime now = QDateTime::currentDateTime();
now = now.addSecs(-now.time().second());
now = now.addMSecs(-now.time().msec());
// Get the list of reminders that are dated at this minute and
// erase them from reminder storage
QList<Appointment> reminders;
engageBufferLock("accessing/updating reminders list");
QMap<QDateTime, Appointment>::iterator it = _aptCache->reminders()->find(now);
// Collect all reminders dated to now
while (it != _aptCache->reminders()->end() && it.key() == now) {
reminders.push_back(*it);
it = _aptCache->reminders()->erase(it);
}
releaseBufferLock("finished accessing reminders list");
// Broadcast new reminders to observers
if (reminders.count() > 0)
emit newReminders(this, reminders);
}
示例12: QQuickView
//-----------------------------------------------------------------------------
MainView::MainView( ) :
QQuickView( ),
_propertiesList( new qan::PropertiesList( this ) )
{
// Dynamic exemple code ------------
Properties* p1 = new qan::Properties( this );
p1->addProperty( "intProperty", QVariant::fromValue< int >( 40 ) );
qDebug( ) << *p1;
qDebug( ) << "--";
QDateTime current = QDateTime::currentDateTimeUtc( );
p1->setProperty( "intProperty", current, 41 );
p1->setProperty( "intProperty", current.addMSecs( 1000 ), 42 );
qDebug( ) << *p1;
qDebug( ) << "--";
//-----------------------------------
// Static exemple code ------------
MyProperties* mp = new MyProperties( this );
qDebug( ) << *mp;
//-----------------------------------
Properties* p = new Properties( this );
p->setObjectName( "MyQanProperties" );
generateRandTimeValues< int >( *p, "intProperty", 15, 15000 ); // Generate random int value over 15s int the "int property"intProperty'
p->addProperty( "intProperty", QVariant::fromValue< int >( 40 ) );
qDebug( ) << *p;
rootContext( )->setContextProperty( "qanPropertiesModel", p->getPropertiesModel( ) );
rootContext( )->setContextProperty( "qanProperties", p );
qan::PropertyGraphModel* graphModel = p->getPropertyGraphModel( "intProperty" );
rootContext( )->setContextProperty( "qanPropertyGraphModel", graphModel );
setSource( QUrl::fromLocalFile( "main.qml" ) );
}
示例13: dateTime
/*!
\fn Convert::dateTime(const QString& mSeconds)
*/
QDateTime Convert::dateTime(const QString& mSeconds) {
static QDateTime zeroTime(QDate(1970,1,1), QTime(0,0), Qt::UTC);
return zeroTime.addMSecs(mSeconds.toULongLong());
}
示例14: loadHistory
void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
{
QDateTime now = historyBaselineDate.addMSecs(-1);
if (since > now)
return;
if (!earliestMessage.isNull())
{
if (earliestMessage < since)
return;
if (earliestMessage < now)
{
now = earliestMessage;
now = now.addMSecs(-1);
}
}
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().publicKey, since, now);
ToxId storedPrevId = previousId;
ToxId prevId;
QList<ChatLine::Ptr> historyMessages;
QDate lastDate(1,0,0);
for (const auto &it : msgs)
{
// Show the date every new day
QDateTime msgDateTime = it.timestamp.toLocalTime();
QDate msgDate = msgDateTime.date();
if (msgDate > lastDate)
{
lastDate = msgDate;
historyMessages.append(ChatMessage::createChatInfoMessage(msgDate.toString(Settings::getInstance().getDateFormat()), ChatMessage::INFO, QDateTime()));
}
// Show each messages
ToxId authorId = ToxId(it.sender);
QString authorStr = authorId.isActiveProfile() ? Core::getInstance()->getUsername() : resolveToxID(authorId);
bool isAction = it.message.startsWith("/me ", Qt::CaseInsensitive);
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr,
isAction ? it.message.right(it.message.length() - 4) : it.message,
isAction ? ChatMessage::ACTION : ChatMessage::NORMAL,
authorId.isActiveProfile(),
QDateTime());
if (!isAction && (prevId == authorId) && (prevMsgDateTime.secsTo(msgDateTime) < getChatLog()->repNameAfter) )
msg->hideSender();
prevId = authorId;
prevMsgDateTime = msgDateTime;
if (it.isSent || !authorId.isActiveProfile())
{
msg->markAsSent(msgDateTime);
}
else
{
if (processUndelivered)
{
int rec;
if (!isAction)
rec = Core::getInstance()->sendMessage(f->getFriendID(), msg->toString());
else
rec = Core::getInstance()->sendAction(f->getFriendID(), msg->toString());
getOfflineMsgEngine()->registerReceipt(rec, it.id, msg);
}
}
historyMessages.append(msg);
}
previousId = storedPrevId;
int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value();
earliestMessage = since;
chatWidget->insertChatlineOnTop(historyMessages);
savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos;
chatWidget->verticalScrollBar()->setValue(savedSliderPos);
}
示例15: readFiles
void ConfigurationParser::readFiles(DataLayer *layer)
{
Q_ASSERT(isStartElement()
&& name() == "files");
QDateTime startDate;
int start = 0;
QDateTime endDate;
int end = 0;
int digits = 0;
QString scheme;
int skip = 0;
while(!atEnd()) {
readNext();
if(isEndElement()) {
break;
}
if(isStartElement()) {
if(name() == "start") {
QXmlStreamAttributes att = attributes();
startDate.setTime(QTime::fromString(att.value("time").toString(), Qt::ISODate));
startDate.setDate(QDate::fromString(att.value("date").toString(), Qt::ISODate));
start = readCharacters().toInt();
}
else if(name() == "end") {
QXmlStreamAttributes att = attributes();
endDate.setTime(QTime::fromString(att.value("time").toString(), Qt::ISODate));
endDate.setDate(QDate::fromString(att.value("date").toString(), Qt::ISODate));
end = readCharacters().toInt();
}
else if(name() == "scheme") {
QXmlStreamAttributes att = attributes();
digits = att.value("digits").toString().toInt();
if(att.hasAttribute("skip")) {
skip = att.value("skip").toString().toInt();
}
scheme = readCharacters();
}
else {
readUnknownElement();
}
}
}
if(startDate.isValid() && endDate.isValid()) {
qint64 spanMSecs = endDate.toMSecsSinceEpoch() - startDate.toMSecsSinceEpoch();
int count = end - start;
qint64 diffMSecs = spanMSecs / count;
for(int i = start; i < end; i += 1 + skip) {
QDateTime fileTime = startDate.addMSecs(diffMSecs * (i - start));
qDebug() << "Time [" << i << "]:" << fileTime.toString();
QString fileName = scheme.arg(i, digits, 10, QChar('0'));
layer->setFileName(fileTime, fileName);
}
}
}