本文整理汇总了C++中QVariant::cast方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::cast方法的具体用法?C++ QVariant::cast怎么用?C++ QVariant::cast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::cast方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readPropertyEntry
QVariant KConfigBase::readPropertyEntry(const char *pKey, QVariant::Type type) const
{
QVariant va;
if(!hasKey(pKey))
return va;
(void)va.cast(type);
return readPropertyEntry(pKey, va);
}
示例2: data
QVariant SqliteResult::data(int i)
{
if (!dataSet)
return QVariant();
if (i >= dataSet->fieldCount()) {
#ifdef FL_DEBUG
qWarning("SqliteResult::data: column %d out of range", i);
#endif
return QVariant();
}
if (qstrcmp(dataSet->fieldName(i), "binario") == 0) { // <- esto es un hack para guardar hexadecimal y interpretar binario.
QString str(dataSet->fv(dataSet->fieldName(i)).get_asString().c_str());
QByteArray ba;
QDataStream dts(ba, IO_WriteOnly);
uint pos = 0;
while (pos < str.length()) {
dts << (Q_UINT8) str.mid(pos, 2).toUShort(0, 16);
pos += 2;
}
return ba;
}
QVariant v = QVariant(QString(dataSet->fv(dataSet->fieldName(i)).get_asString().c_str()));
if (v.toString().isEmpty()) {
QVariant vv;
fType type = dataSet->fv(dataSet->fieldName(i)).get_fType();
if (!type)
vv.cast(QVariant::String);
else
vv.cast(QVariant::Double);
return vv;
} else
return v;
}
示例3: alterTable
//.........这里部分代码省略.........
if ((oldMTD != newMTD) && oldMTD)
delete oldMTD;
if (newMTD)
delete newMTD;
return false;
}
if (fieldList->isEmpty()) {
#ifdef FL_DEBUG
qWarning("FLManager::alterTable : " + QApplication::tr("Los nuevos metadatos no tienen campos."));
#endif
db_->dbAux() ->rollback();
if ((oldMTD != newMTD) && oldMTD)
delete oldMTD;
if (newMTD)
delete newMTD;
return false;
}
QVariant v;
bool ok = true;
while (oldCursor.next()) {
newBuffer = newCursor.primeInsert();
QDictIterator<FLFieldMetaData> it(*fieldList);
while ((newField = it.current()) != 0) {
++it;
oldField = oldMTD->field(newField->name());
if (!oldField || !oldCursor.field(oldField->name())) {
if (!oldField)
oldField = newField;
v = newField->defaultValue();
v.cast(FLFieldMetaData::flDecodeType(newField->type()));
} else {
v = oldCursor.value(newField->name());
if ((!oldField->allowNull() || !newField->allowNull()) &&
(v.isNull() || !v.isValid())) {
QVariant defVal(newField->defaultValue());
if (!defVal.isNull() && defVal.isValid())
v = defVal;
}
if (!v.cast(newBuffer->value(newField->name()).type())) {
#ifdef FL_DEBUG
qWarning("FLManager::alterTable : " +
QApplication::tr("Los tipos del campo %1 no son compatibles. Se introducirá un valor nulo.")
.arg(newField->name()));
#endif
}
}
if ((!oldField->allowNull() || !newField->allowNull()) && (v.isNull() || !v.isValid())) {
switch (oldField->type()) {
case QVariant::Int:
case FLFieldMetaData::Serial:
case QVariant::UInt:
case QVariant::Bool:
case FLFieldMetaData::Unlock:
v = int(0);
break;
case QVariant::Double:
v = double(0.0);
break;
case QVariant::Time:
v = QTime::currentTime();
break;
case QVariant::Date: