本文整理汇总了C++中QVariant::toHash方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::toHash方法的具体用法?C++ QVariant::toHash怎么用?C++ QVariant::toHash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::toHash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadVariable
bool SettingsManager::loadVariable(QIODevice* in, bool append)
{
if (!in || !in->isOpen() || !in->isReadable()) {
qDebug() << "SettingsManager::loadVariableFromFile: Is not open or is not readable";
return false;
}
QDataStream stream(in);
stream.setVersion(QDataStream::Qt_4_6);
QVariant v;
stream >> v;
if (append) {
QHash<QString, QVariant> hash = v.toHash();
QHash<QString, QVariant>::const_iterator i = hash.constBegin();
while (i != hash.constEnd()) {
m_variables.insert(i.key(), i.value());
++i;
}
}
else {
m_variables = v.toHash();
}
return true;
}
示例2: endElement
bool FBXMLHandler::endElement( const QString & /*namespaceURI*/,
const QString & /*localName*/,
const QString & /*qName*/ )
{
flushCharacters();
QVariant c = iStack [iStack.count() - 1] ;
QString name = topName();
iStack.removeLast();
iNameStack.removeLast();
if (!iStack.count())
{
iRootObject = c;
iRootName = name;
}
else
{
QVariant tC = iStack[iStack.count() - 1] ;
if (tC.isNull())
{
tC = QVariantHash();
iStack.replace(iStack.count() - 1, tC);
}
if (tC.type() == QVariant::List)
{
QVariantList list = tC.toList();
list.append( c.toHash() );
iStack.replace( iStack.count() - 1 , list);
}
else if (tC.type() == QVariant::Hash)
{
QVariantHash hash = tC.toHash();
if (c.isNull())
{
c = QString("");
}
hash.insert( name, c );
iStack.replace( iStack.count() - 1 , hash);
}
}
return true;
}
示例3: breakpoint
void TarryTown::breakpoint() {
qDebug() << "Entering debugging mode";
QTextStream in(stdin);
QTextStream out(stdout);
QString to_eval;
while (to_eval != "cont") {
out << "> ";
out.flush();
to_eval = in.readLine();
to_eval = to_eval.replace(QString("\n"),"");
if (to_eval != "cont") {
QScriptValue result = p_engine->evaluate(to_eval);
if (p_engine->hasUncaughtException()) {
QStringList backtrace = p_engine->uncaughtExceptionBacktrace();
fprintf (stderr, " %s\n\n", qPrintable(backtrace.join("\n")));
} else {
QVariant value = result.toVariant();
if (value.type() == QMetaType::QVariantMap) {
qDebug() << "=> " << value.toMap();
} else if (value.type() == QMetaType::QVariantList) {
qDebug() << "=> " << value.toList();
} else if (value.type() == QMetaType::QVariantHash) {
qDebug() << "=> " << value.toHash();
} else if (value.type() == QMetaType::QString) {
qDebug() << "=> \n" << value.toString();
} else {
qDebug() << "=> " << value;
}
} // if (p_engine->hasUncaughtException())
}
}
}
示例4: setOptionsForQObject
void setOptionsForQObject(const QVariant& opt, QObject *obj)
{
if (!opt.isValid())
return;
qDebug() << QStringLiteral("set %1(%2) meta properties:").arg(QLatin1String(obj->metaObject()->className())).arg(obj->objectName());
if (opt.type() == QVariant::Hash) {
QVariantHash options(opt.toHash());
if (options.isEmpty())
return;
QHashIterator<QString, QVariant> i(options);
while (i.hasNext()) {
i.next();
if (i.value().type() == QVariant::Hash) // for example "vaapi": {...}
continue;
obj->setProperty(i.key().toUtf8().constData(), i.value());
qDebug("%s=>%s", i.key().toUtf8().constData(), i.value().toByteArray().constData());
}
}
if (opt.type() != QVariant::Map)
return;
QVariantMap options(opt.toMap());
if (options.isEmpty())
return;
QMapIterator<QString, QVariant> i(options);
while (i.hasNext()) {
i.next();
if (i.value().type() == QVariant::Map) // for example "vaapi": {...}
continue;
obj->setProperty(i.key().toUtf8().constData(), i.value());
qDebug("%s=>%s", i.key().toUtf8().constData(), i.value().toByteArray().constData());
}
}
示例5: it
QByteArray
toJson( const QVariant &variant, bool* ok )
{
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
QVariant _variant = variant;
if ( variant.type() == QVariant::Hash )
{
// QJsonDocument cannot deal with QVariantHash, so convert.
const QVariantHash hash = variant.toHash();
QVariantMap map;
QHashIterator<QString, QVariant> it(hash);
while ( it.hasNext() )
{
it.next();
map.insert( it.key(), it.value() );
}
_variant = map;
}
QJsonDocument doc = QJsonDocument::fromVariant( _variant );
if ( ok != NULL )
{
*ok = !doc.isNull();
}
return doc.toJson( QJsonDocument::Compact );
#else
QJson::Serializer serializer;
return serializer.serialize( variant, ok );
#endif
}
示例6: exportAllFlashVariants
/*!
\~english
Exports the all flash variants.
\~japanese
すべてのフラッシュオブジェクトをエクスポートする
*/
void TActionController::exportAllFlashVariants()
{
QVariant var = sessionStore.take(FLASH_VARS_SESSION_KEY);
if (!var.isNull()) {
exportVariants(var.toHash());
}
}
示例7: handleInfo
void Keyboard::handleInfo(QVariant const& properties)
{
bool ok = false;
QVariantHash items = properties.toHash();
QString newSize = items[QString::fromLatin1("size")].toString();
QVariantHash locale = items[QString::fromLatin1("locale")].toHash();
int intSize = newSize.toInt(&ok);
if (!locale.isEmpty())
{
QString languageId = locale[QString::fromLatin1("languageId")].toString();
QString countryId = locale[QString::fromLatin1("countryId")].toString();
if (!languageId.isEmpty())
mLanguageId = languageId;
if (!countryId.isEmpty())
mCountryId = countryId;
}
if (ok && intSize != mKeyboardHeight) {
mKeyboardHeight = intSize;
emit notifyHeightChanged(mKeyboardHeight);
}
#ifdef PPS_KEYBOARD_DEBUG
qDebug() << "Keyboard: height:" << mKeyboardHeight << " languageId:" << mLanguageId
<< " countryId:" << mCountryId;
#endif
}
示例8: luaPush
void LuaEngine::luaPush(const QVariant& variant)
{
switch (variant.type())
{
case QVariant::Bool:
{
luaPush(variant.toBool());
break;
}
case QVariant::String:
{
luaPush(variant.toString());
break;
}
case QVariant::Int:
{
luaPush(variant.toInt());
break;
}
case QVariant::Map:
{
luaPush(variant.toMap());
break;
}
case QVariant::Hash:
{
luaPush(variant.toHash());
break;
}
default:
break;
}
}
示例9: acceptsValueImpl
FormGenAcceptResult FormGenRecordComposition::acceptsValueImpl(const QVariant &val) const
{
if( variantType(val) != QMetaType::QVariantHash )
return FormGenAcceptResult::reject({}, val);
QVariantHash hash = val.toHash();
QStringList valueStringList;
QSet<QString> processedTags;
for( const auto &elm : mElements ) {
auto elementAccepts = elm.element->acceptsValue(hash.value(elm.tag));
if( ! elementAccepts.acceptable ) {
QString path = elm.tag;
if( ! elementAccepts.path.isEmpty() )
path += QString("/%1").arg(elementAccepts.path);
return FormGenAcceptResult::reject(path, elementAccepts.value);
}
valueStringList.append(FormGenElement::keyStringValuePair(elm.tag, elementAccepts.valueString));
processedTags.insert(elm.tag);
}
QSet<QString> remainingTags = hash.keys().toSet() - processedTags;
if( ! remainingTags.isEmpty() )
return FormGenAcceptResult::reject(*remainingTags.cbegin(),
hash.value(*remainingTags.cbegin()));
return FormGenAcceptResult::accept(val, FormGenElement::objectString(valueStringList));
}
示例10: fromQVariant
Command Command::fromQVariant(const QVariant &variant)
{
const QHash<QString, QVariant> hash = variant.toHash();
const QString namePref = QLatin1String("Name");
const QString executablePref = QLatin1String("Command");
const QString argumentsPref = QLatin1String("Arguments");
const QString workingDirectoryPref = QLatin1String("WorkingDirectory");
const QString enablePref = QLatin1String("Enabled");
const QString shortcutPref = QLatin1String("Shortcut");
const QString showOutputPref = QLatin1String("ShowOutput");
const QString saveBeforeExecutePref = QLatin1String("SaveBeforeExecute");
Command command;
if (hash.contains(enablePref))
command.isEnabled = hash[enablePref].toBool();
if (hash.contains(namePref))
command.name = hash[namePref].toString();
if (hash.contains(executablePref))
command.executable = hash[executablePref].toString();
if (hash.contains(argumentsPref))
command.arguments = hash[argumentsPref].toString();
if (hash.contains(workingDirectoryPref))
command.workingDirectory = hash[workingDirectoryPref].toString();
if (hash.contains(shortcutPref))
command.shortcut = hash[shortcutPref].value<QKeySequence>();
if (hash.contains(showOutputPref))
command.showOutput = hash[showOutputPref].toBool();
if (hash.contains(saveBeforeExecutePref))
command.saveBeforeExecute = hash[saveBeforeExecutePref].toBool();
return command;
}
示例11: persistSession
void Session::persistSession(const QString &sessionId, const QVariant &data) const
{
const QString &sessionFile = SessionPrivate::filePath(sessionId);
const QVariantHash &hash = data.toHash();
if (hash.isEmpty()) {
qCDebug(C_SESSION) << "Clearing session values on" << sessionFile;
bool ret = QFile::remove(sessionFile);
if (!ret) {
QSettings settings(sessionFile, QSettings::IniFormat);
settings.clear();
}
} else {
qCDebug(C_SESSION) << "Persisting session values to" << sessionFile;
QSettings settings(sessionFile, QSettings::IniFormat);
settings.beginGroup(QLatin1String("Data"));
QVariantHash::ConstIterator it = hash.constBegin();
while (it != hash.constEnd()) {
if (it.value().isNull()) {
settings.remove(it.key());
} else {
settings.setValue(it.key(), it.value());
}
++it;
}
settings.endGroup();
}
}
示例12: fromVariant
bool ZrpcResponsePacket::fromVariant(const QVariant &in)
{
if(in.type() != QVariant::Hash)
return false;
QVariantHash obj = in.toHash();
if(!obj.contains("id") || obj["id"].type() != QVariant::ByteArray)
return false;
id = obj["id"].toByteArray();
if(!obj.contains("success") || obj["success"].type() != QVariant::Bool)
return false;
success = obj["success"].toBool();
value.clear();
condition.clear();
if(success)
{
if(!obj.contains("value"))
return false;
value = obj["value"];
}
else
{
if(!obj.contains("condition") || obj["condition"].type() != QVariant::ByteArray)
return false;
condition = obj["condition"].toByteArray();
}
return true;
}
示例13: EvaluateSubExpression
QString EvaluateSubExpression(const QString& subexpr, const QVariant& v) {
if (subexpr.size() == 0) {
// limit the displayed decimal places
if ((QMetaType::Type)v.type() == QMetaType::Double) {
return QString::number(v.toDouble(), 'f', 2);
}
return v.toString();
} else if (subexpr.at(0) == '[') {
int rightbracket = subexpr.indexOf(']');
if (rightbracket > 0) {
bool ok = false;
int index = subexpr.mid(1, rightbracket-1).toInt(&ok);
if (ok && (QMetaType::Type)v.type() == QMetaType::QVariantList) {
return EvaluateSubExpression(subexpr.mid(rightbracket + 1),
v.toList().at(index));
}
}
} else {
int dot = subexpr.indexOf('.');
QString key = subexpr.mid(0, dot);
if ((QMetaType::Type)v.type() == QMetaType::QVariantHash) {
QHash<QString, QVariant> h = v.toHash();
QHash<QString, QVariant>::const_iterator it = h.find(key);
if (it != h.end())
return EvaluateSubExpression(subexpr.mid(key.length() + 1), *it);
} else if ((QMetaType::Type)v.type() == QMetaType::QVariantMap) {
QMap<QString, QVariant> h = v.toMap();
QMap<QString, QVariant>::const_iterator it = h.find(key);
if (it != h.end())
return EvaluateSubExpression(subexpr.mid(key.length() + 1), *it);
}
}
return "";
}
示例14: if
bool ConnectionManager2::applyConfig(QVariant const & config)
{
if (config.type() != QVariant::List)
return false;
QList<Connection *> newConns;
struct cleanup
{
QList<Connection *> & conns;
cleanup(QList<Connection *> & conns) : conns(conns) {}
~cleanup() { for (int i = 0; i < conns.size(); ++i) conns[i]->releaseAll(); }
} cleanupGuard(newConns);
QList<QVariant> const & connConfigs = config.toList();
for (int i = 0; i < connConfigs.size(); ++i)
{
if (connConfigs[i].type() != QVariant::Hash)
return false;
QHash<QString, QVariant> const & connConfig = connConfigs[i].toHash();
QVariant typev = connConfig.value("type");
if (typev.type() != QVariant::String)
return false;
QString const & type = typev.toString();
ConnectionPointer<Connection> conn;
if (type == "serial_port")
conn.reset(new SerialPort());
else if (type == "tcp_client")
conn.reset(new TcpSocket());
else if (type == "udp_socket")
conn.reset(new UdpSocket());
#ifdef HAVE_LIBYB
else if (type == "usb_yb_acm")
conn.reset(new UsbAcmConnection2(m_yb_runner));
#endif
if (!conn)
return false;
QVariant settings = connConfig.value("settings");
if (settings.type() != QVariant::Hash || !conn->applyConfig(settings.toHash()))
return false;
newConns.push_back(conn.data());
conn.take();
}
this->clearUserOwnedConns();
while (!newConns.empty())
{
this->addUserOwnedConn(newConns.back());
newConns.pop_back();
}
return true;
}
示例15: variantMapValue
QVariant variantMapValue(const QVariant& value, const QString& key)
{
if (value.userType() == QVariant::Map) {
return value.toMap().value(key);
} else {
return value.toHash().value(key);
}
}