本文整理汇总了C++中QDateTime::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ QDateTime::isValid方法的具体用法?C++ QDateTime::isValid怎么用?C++ QDateTime::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDateTime
的用法示例。
在下文中一共展示了QDateTime::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_reminderCheckBox_clicked
/**
* @brief Determines whether to show or hide the reminder date time edit
*/
void TodoDialog::on_reminderCheckBox_clicked() {
if (ui->reminderCheckBox->isChecked()) {
QDateTime alarmDate = currentCalendarItem.getAlarmDate();
// if no alarm date was set use the current date plus 1h
if (!alarmDate.isValid()) {
alarmDate = QDateTime::currentDateTime().addSecs(3600);
}
ui->reminderDateTimeEdit->setDateTime(alarmDate);
ui->reminderDateTimeEdit->show();
} else {
ui->reminderDateTimeEdit->hide();
}
}
示例2: getResponse
void Easter::getResponse(const QtSoapMessage &message)
{
if (message.isFault()) {
qDebug("Error: %s", qPrintable(message.faultString().toString()));
}
else {
QString res = message.returnValue().toString();
QDateTime dt = QDateTime::fromString(res, Qt::ISODate);
if (dt.isValid())
res = QLocale::c().toString(dt.date());
qDebug("Easter is: %s", res.toLatin1().constData());
}
QCoreApplication::quit();
}
示例3: setDateTime
void QgsDateTimeEdit::setDateTime( const QDateTime &dateTime )
{
mIsEmpty = false;
// set an undefined date
if ( !dateTime.isValid() || dateTime.isNull() )
{
clear();
}
else
{
QDateTimeEdit::setDateTime( dateTime );
changed( dateTime );
}
}
示例4: RemoveRecorded
bool Dvr::RemoveRecorded( int nChanId,
const QDateTime &dStartTime )
{
if (nChanId <= 0 || !dStartTime.isValid())
throw( QString("Channel ID or StartTime appears invalid."));
bool bResult = false;
ProgramInfo *pInfo = new ProgramInfo(nChanId, dStartTime);
if (pInfo->HasPathname())
bResult = RemoteDeleteRecording(nChanId, dStartTime, true, false);
return bResult;
}
示例5: RFC822TimeToQDateTime
QDateTime RFC822TimeToQDateTime(const QString& t)
{
QMap<QString, int> TimezoneOffsets;
if (t.size() < 20)
return QDateTime();
QString time = t.simplified();
short int hoursShift = 0, minutesShift = 0;
QStringList tmp = time.split(' ');
if (tmp.isEmpty())
return QDateTime();
if (tmp. at(0).contains(QRegExp("\\D")))
tmp.removeFirst();
if (tmp.size() != 5)
return QDateTime();
QString timezone = tmp.takeAt(tmp.size() -1);
if (timezone.size() == 5)
{
bool ok;
int tz = timezone.toInt(&ok);
if(ok)
{
hoursShift = tz / 100;
minutesShift = tz % 100;
}
}
else
hoursShift = TimezoneOffsets.value(timezone, 0);
if (tmp.at(0).size() == 1)
tmp[0].prepend("0");
tmp [1].truncate(3);
time = tmp.join(" ");
QDateTime result;
if (tmp.at(2).size() == 4)
result = QLocale::c().toDateTime(time, "dd MMM yyyy hh:mm:ss");
else
result = QLocale::c().toDateTime(time, "dd MMM yy hh:mm:ss");
if (result.isNull() || !result.isValid())
return QDateTime();
result = result.addSecs(hoursShift * 3600 * (-1) + minutesShift *60 * (-1));
result.setTimeSpec(Qt::UTC);
return result;
}
示例6: parseName
QString TimeSource::parseName(const QString &name)
{
m_userDateTime = false;
if (!name.contains('|')) {
// the simple case where it's just a timezone request
return name;
}
// the various keys we recognize
static const QString latitude = I18N_NOOP("Latitude");
static const QString longitude = I18N_NOOP("Longitude");
static const QString solar = I18N_NOOP("Solar");
static const QString moon = I18N_NOOP("Moon");
static const QString datetime = I18N_NOOP("DateTime");
// now parse out what we got handed in
const QStringList list = name.split('|', QString::SkipEmptyParts);
const int listSize = list.size();
for (int i = 1; i < listSize; ++i) {
const QString arg = list[i];
const int n = arg.indexOf('=');
if (n != -1) {
const QString key = arg.mid(0, n);
const QString value = arg.mid(n + 1);
if (key == latitude) {
m_latitude = value.toDouble();
} else if (key == longitude) {
m_longitude = value.toDouble();
} else if (key == datetime) {
QDateTime dt = QDateTime::fromString(value, Qt::ISODate);
if (dt.isValid()) {
setData(I18N_NOOP("DateTime"), dt);
m_userDateTime = true;
}
}
} else if (arg == solar) {
m_solarPosition = true;
} else if (arg == moon) {
m_moonPosition = true;
}
}
// timezone is first item ...
return list.at(0);
}
示例7: sendAgentStatus
void Client::sendAgentStatus(QString username, QString fullname, Client::Phone phone, int handle, int abandoned, QString group, QDateTime login, QString address, QString extension)
{
bool groupEmpty = group.isEmpty();
socketOut.writeStartElement("agent");
socketOut.writeTextElement("username", username);
socketOut.writeTextElement("fullname", fullname);
if (!groupEmpty)
socketOut.writeTextElement("group", group);
socketOut.writeTextElement("handle", QString::number(handle));
socketOut.writeTextElement("abandoned", QString::number(abandoned));
if (login.isValid())
socketOut.writeTextElement("login", login.toString("yyyy-MM-dd HH:mm:ss"));
socketOut.writeTextElement("time", phone.time.toString("yyyy-MM-dd HH:mm:ss"));
if (!address.isEmpty())
socketOut.writeTextElement("address", address);
if (!extension.isEmpty())
socketOut.writeTextElement("extension", extension);
socketOut.writeStartElement("phone");
socketOut.writeAttribute("status", phone.status);
socketOut.writeAttribute("outbound", phone.outbound ? "true" : "false");
if (!groupEmpty)
socketOut.writeAttribute("group", group);
if (!phone.channel.isEmpty()) {
socketOut.writeAttribute(phone.active ? "activechannel" : "passivechannel", phone.channel);
}
if (!phone.dnis.isEmpty()) {
socketOut.writeEmptyElement(phone.active ? "callee" : "caller");
socketOut.writeAttribute("dnis", phone.dnis);
}
socketOut.writeEndElement(); // phone
socketOut.writeEndElement(); // agent
socket->write("\n");
}
示例8: createFile
void TestDir::createFile(const QString& path, const QByteArray& data, const QDateTime& time)
{
QString absolutePath = path;
makePathAbsoluteAndCreateParents(absolutePath);
QFile f(absolutePath);
f.open(QIODevice::WriteOnly);
f.write(data);
f.close();
if (time.isValid()) {
setTimeStamp(absolutePath, time);
}
Q_ASSERT(QFile::exists(absolutePath));
}
示例9: resizeTo
void Column::Private::setDateTimeAt(int row, const QDateTime& new_value)
{
if (d_data_type != SciDAVis::TypeQDateTime) return;
emit d_owner->dataAboutToChange(d_owner);
if (row >= rowCount())
{
if (row+1-rowCount() > 1) // we are adding more than one row in resizeTo()
d_validity.setValue(Interval<int>(rowCount(), row-1), true);
resizeTo(row+1);
}
static_cast< QList<QDateTime>* >(d_data)->replace(row, new_value);
d_validity.setValue(Interval<int>(row, row), !new_value.isValid());
emit d_owner->dataChanged(d_owner);
}
示例10: GetRecording
QFileInfo Content::GetRecording( int nChanId,
const QDateTime &recstarttsRaw )
{
if (!recstarttsRaw.isValid())
throw( "StartTime is invalid" );
// ------------------------------------------------------------------
// Read Recording From Database
// ------------------------------------------------------------------
QDateTime recstartts = recstarttsRaw.toUTC();
ProgramInfo pginfo((uint)nChanId, recstartts);
if (!pginfo.GetChanID())
{
LOG(VB_UPNP, LOG_ERR, QString("GetRecording - for '%1' failed")
.arg(ProgramInfo::MakeUniqueKey(nChanId, recstartts)));
return QFileInfo();
}
if (pginfo.GetHostname().toLower() != gCoreContext->GetHostName().toLower())
{
// We only handle requests for local resources
QString sMsg =
QString("GetRecording: Wrong Host '%1' request from '%2'.")
.arg( gCoreContext->GetHostName())
.arg( pginfo.GetHostname() );
LOG(VB_UPNP, LOG_ERR, sMsg);
throw HttpRedirectException( pginfo.GetHostname() );
}
QString sFileName( GetPlaybackURL(&pginfo) );
// ----------------------------------------------------------------------
// check to see if the file exists
// ----------------------------------------------------------------------
if (QFile::exists( sFileName ))
return QFileInfo( sFileName );
return QFileInfo();
}
示例11: Track
Track
ITunesLibrary::Track::lastfmTrack() const
{
// TODO: why are we doing this? It will return true for manual tracks as it checks the path.
if ( isNull() )
return Track();
COM::ITunesTrack i = d->i;
// These will throw if something goes wrong
IPodScrobble t;
t.setArtist( QString::fromStdWString( i.artist() ) );
t.setTitle( QString::fromStdWString( i.track() ) );
t.setDuration( i.duration() );
t.setAlbum( QString::fromStdWString( i.album() ) );
t.setPlayCount( i.playCount() );
QDateTime stamp = QDateTime::fromString( QString::fromStdWString( i.lastPlayed() ), "yyyy-MM-dd hh:mm:ss" );
if ( stamp.isValid() )
{
uint unixTime = stamp.toTime_t();
// This is to prevent the spurious scrobble bug that can happen if iTunes is
// shut during twiddling. The timestamp returned in that case was FFFFFFFF
// so let's check for that.
if ( unixTime == 0xFFFFFFFF )
{
qWarning() << "Caught a 0xFFFFFFFF timestamp, assume it's the scrobble of spury:" << QString::fromStdWString( i.toString() );
return Track();
}
t.setTimestamp( stamp );
}
else
{
// If we don't have a valid timestamp, set to current time. Should work. We hope.
qWarning() << "Invalid timestamp, set to current:" << QString::fromStdWString( i.toString() );
t.setTimestamp( QDateTime::currentDateTime() );
}
const QString path = QString::fromStdWString( i.path() );
t.setUrl( QUrl::fromLocalFile( QFileInfo( path ).absoluteFilePath() ) );
t.setSource( Track::MediaDevice );
return t;
}
示例12: toSqlValue
QString utils::toSqlValue(QVariant value)
{
QString toret;
bool ok;
value.toDouble(&ok);
if(ok){
toret = QString::number(value.toDouble());
}else{
QDateTime d = value.toDateTime();
if(d.isValid()){
toret = "'" + value.toDateTime().toString("yyyy-MM-dd hh:mm:ss") + "'";
}else{
toret = "'" + value.toString() + "'";
};
};
return toret;
}
示例13: fromDateTime
SchemaTime::Ptr SchemaTime::fromDateTime(const QDateTime &dt)
{
Q_ASSERT(dt.isValid());
/* Singleton value, allocated once instead of each time it's needed. */
// STATIC DATA
static const QDate time_defaultDate(AbstractDateTime::DefaultYear,
AbstractDateTime::DefaultMonth,
AbstractDateTime::DefaultDay);
QDateTime result;
copyTimeSpec(dt, result);
result.setDate(time_defaultDate);
result.setTime(dt.time());
return SchemaTime::Ptr(new SchemaTime(result));
}
示例14: init
void UiCodeModelSupport::init() const
{
m_initialized = true;
QDateTime sourceTime = QFileInfo(m_sourceName).lastModified();
QFileInfo uiHeaderFileInfo(m_fileName);
QDateTime uiHeaderTime = uiHeaderFileInfo.exists() ? uiHeaderFileInfo.lastModified() : QDateTime();
if (uiHeaderTime.isValid() && (uiHeaderTime > sourceTime)) {
QFile file(m_fileName);
if (file.open(QFile::ReadOnly | QFile::Text)) {
if (debug)
qDebug()<<"ui*h file is more recent then source file, using information from ui*h file"<<m_fileName;
QTextStream stream(&file);
m_contents = stream.readAll().toUtf8();
m_cacheTime = uiHeaderTime;
return;
}
}
if (debug)
qDebug()<<"ui*h file not found, or not recent enough, trying to create it on the fly";
QFile file(m_sourceName);
if (file.open(QFile::ReadOnly | QFile::Text)) {
QTextStream stream(&file);
const QString contents = stream.readAll();
if (runUic(contents)) {
if (debug)
qDebug()<<"created on the fly";
return;
} else {
// uic run was unsuccesfull
if (debug)
qDebug()<<"uic run wasn't succesfull";
m_cacheTime = QDateTime ();
m_contents = QByteArray();
// and if the header file wasn't there, next time we need to update
// all of the files that include this header
if (!uiHeaderFileInfo.exists())
m_updateIncludingFiles = true;
return;
}
} else {
if (debug)
qDebug()<<"Could open "<<m_sourceName<<"needed for the cpp model";
m_contents = QByteArray();
}
}
示例15: debug
StatSyncing::ScrobblingService::ScrobbleError
ScrobblerAdapter::scrobble( const Meta::TrackPtr &track, double playedFraction,
const QDateTime &time )
{
Q_ASSERT( track );
if( isToBeSkipped( track ) )
{
debug() << "scrobble(): refusing track" << track->prettyUrl()
<< "- contains label:" << m_config->filteredLabel() << "which is marked to be skipped";
return SkippedByUser;
}
if( track->length() * qMin( 1.0, playedFraction ) < 30 * 1000 )
{
debug() << "scrobble(): refusing track" << track->prettyUrl() << "- played time ("
<< track->length() / 1000 << "*" << playedFraction << "s) shorter than 30 s";
return TooShort;
}
int playcount = qRound( playedFraction );
if( playcount <= 0 )
{
debug() << "scrobble(): refusing track" << track->prettyUrl() << "- played "
<< "fraction (" << playedFraction * 100 << "%) less than 50 %";
return TooShort;
}
lastfm::MutableTrack lfmTrack;
copyTrackMetadata( lfmTrack, track );
// since liblastfm >= 1.0.3 it interprets following extra property:
lfmTrack.setExtra( "playCount", QString::number( playcount ) );
lfmTrack.setTimeStamp( time.isValid() ? time : QDateTime::currentDateTime() );
debug() << "scrobble: " << lfmTrack.artist() << "-" << lfmTrack.album() << "-"
<< lfmTrack.title() << "source:" << lfmTrack.source() << "duration:"
<< lfmTrack.duration();
m_scrobbler.cache( lfmTrack );
m_scrobbler.submit(); // since liblastfm 1.0.7, submit() is not called automatically upon cache()
switch( lfmTrack.scrobbleStatus() )
{
case lastfm::Track::Cached:
case lastfm::Track::Submitted:
return NoError;
case lastfm::Track::Null:
case lastfm::Track::Error:
break;
}
return BadMetadata;
}