本文整理汇总了C++中QJsonObject函数的典型用法代码示例。如果您正苦于以下问题:C++ QJsonObject函数的具体用法?C++ QJsonObject怎么用?C++ QJsonObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QJsonObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: type
/*!
Converts the value to an object and returns it.
If type() is not Object, a QJsonObject() will be returned.
*/
QJsonObject QJsonValue::toObject() const
{
if (!d || t != Object)
return QJsonObject();
return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base));
}
示例2: f
void LogSelectorForm::check_config(){
QString conf_path = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation).append("/config.json");
QFile f(conf_path);
if (!f.exists()){
QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
QJsonValue algorithm("KMeans");
QJsonObject param = QJsonObject();
param.insert("n_clusters",4);
QJsonArray features;
features.append(QString("count_domain_with_numbers"));
features.append(QString("average_domain_length"));
features.append(QString("std_domain_length"));
features.append(QString("count_request"));
features.append(QString("average_requisition_degree"));
features.append(QString("std_requisition_degree"));
features.append(QString("minimum_requisition_degree"));
QJsonObject target = QJsonObject();
target.insert("algorithm",algorithm);
target.insert("features",features);
target.insert("param",param);
QJsonDocument config_out(target);
QFile out_file(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation).append("/config.json"));
out_file.open(QIODevice::WriteOnly | QIODevice::Text);
out_file.write(config_out.toJson());
out_file.close();
}
}
示例3: isObject
/*!
Returns the QJsonObject contained in the document.
Returns an empty object if the document contains an
array.
\sa isObject(), array(), setObject()
*/
QJsonObject QJsonDocument::object() const
{
if (d) {
QJsonPrivate::Base *b = d->header->root();
if (b->isObject())
return QJsonObject(d, static_cast<QJsonPrivate::Object *>(b));
}
return QJsonObject();
}
示例4: fromVariantHash
/*!
Converts the variant map \a map to a QJsonObject.
The keys in \a map will be used as the keys in the JSON object,
and the QVariant values will be converted to JSON values.
\sa fromVariantHash(), toVariantMap(), QJsonValue::fromVariant()
*/
QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map)
{
QJsonObject object;
if (map.isEmpty())
return object;
object.detach2(1024);
QVector<QJsonPrivate::offset> offsets;
QJsonPrivate::offset currentOffset;
currentOffset = sizeof(QJsonPrivate::Base);
// the map is already sorted, so we can simply append one entry after the other and
// write the offset table at the end
for (QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it) {
QString key = it.key();
QJsonValue val = QJsonValue::fromVariant(it.value());
bool latinOrIntValue;
int valueSize = QJsonPrivate::Value::requiredStorage(val, &latinOrIntValue);
bool latinKey = QJsonPrivate::useCompressed(key);
int valueOffset = sizeof(QJsonPrivate::Entry) + QJsonPrivate::qStringSize(key, latinKey);
int requiredSize = valueOffset + valueSize;
if (!object.detach2(requiredSize + sizeof(QJsonPrivate::offset))) // offset for the new index entry
return QJsonObject();
QJsonPrivate::Entry *e = reinterpret_cast<QJsonPrivate::Entry *>(reinterpret_cast<char *>(object.o) + currentOffset);
e->value.type = val.t;
e->value.latinKey = latinKey;
e->value.latinOrIntValue = latinOrIntValue;
e->value.value = QJsonPrivate::Value::valueToStore(val, (char *)e - (char *)object.o + valueOffset);
QJsonPrivate::copyString((char *)(e + 1), key, latinKey);
if (valueSize)
QJsonPrivate::Value::copyData(val, (char *)e + valueOffset, latinOrIntValue);
offsets << currentOffset;
currentOffset += requiredSize;
object.o->size = currentOffset;
}
// write table
object.o->tableOffset = currentOffset;
if (!object.detach2(sizeof(QJsonPrivate::offset)*offsets.size()))
return QJsonObject();
memcpy(object.o->table(), offsets.constData(), offsets.size()*sizeof(uint));
object.o->length = offsets.size();
object.o->size = currentOffset + sizeof(QJsonPrivate::offset)*offsets.size();
return object;
}
示例5: jsonDir
QJsonObject DCMotor::getDirectionJson()
{
QJsonValue jsonDir(dirn);
return QJsonObject({
QPair<QString, QJsonValue>(directionKey, jsonDir)
});
}
示例6: type
/*!
Converts the value to an object and returns it.
If type() is not Object, the \a defaultValue will be returned.
*/
QJsonObject QJsonValue::toObject(const QJsonObject &defaultValue) const
{
if (!d || t != Object)
return defaultValue;
return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base));
}
示例7: loadJsonObjectFromResource
QJsonObject loadJsonObjectFromResource(const QString &resource, QString *error)
{
QFile file(resource);
if (file.open(QFile::ReadOnly)) {
QJsonParseError parseError;
QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &parseError);
if (parseError.error == QJsonParseError::NoError) {
if (doc.isObject())
return doc.object();
else {
if (error) {
*error = QStringLiteral("JSON doesn't contain a main object.");
}
}
} else {
if (error) {
*error = parseError.errorString();
}
}
} else {
if (error) {
*error = QStringLiteral("Unable to open file.");
}
}
return QJsonObject();
}
示例8: jsonPWM
QJsonObject DCMotor::getPwmJson()
{
QJsonValue jsonPWM(pwmValue);
return QJsonObject({
QPair<QString, QJsonValue>(pwmKey, jsonPWM)
});
}
示例9: QJsonObject
bool CategoryParser::parse(const QString &fileName)
{
m_exploreObject = QJsonObject();
m_tree.clear();
m_errorString.clear();
QFile mappingFile(fileName);
if (mappingFile.open(QIODevice::ReadOnly)) {
QJsonDocument document = QJsonDocument::fromJson(mappingFile.readAll());
if (document.isObject()) {
QJsonObject docObject = document.object();
if (docObject.contains(QLatin1String("offline_explore"))) {
m_exploreObject = docObject.value(QLatin1String("offline_explore"))
.toObject();
if (m_exploreObject.contains(QLatin1String("ROOT"))) {
processCategory(0, QString());
return true;
}
} else {
m_errorString = fileName + QLatin1String("does not contain the "
"offline_explore property");
return false;
}
} else {
m_errorString = fileName + QLatin1String("is not an json object");
return false;
}
}
m_errorString = QString::fromLatin1("Unable to open ") + fileName;
return false;
}
示例10: QJsonValue
void collectmailsesb::__testjson()
{
QJsonDocument doc;
QJsonObject data;
data.insert("data", QJsonValue(QJsonObject()));
{
//QJsonObject esb;
//esb.insert("[ESB]", QJsonValue(QJsonArray()));
QJsonArray a;
a.append(QJsonValue(QString("ae")));
data.insert("data2", QJsonValue(a));
QJsonArray aa = data.value("data2").toArray();
aa.append(QJsonValue(QString("aee")));
data.remove("data2");
data.insert("data2", QJsonValue(aa));
//doc.object().value("data").toObject().insert("[ESB]", QJsonValue(a));
//QJsonObject data2;
//data2.insert("data2", QJsonValue(QJsonObject()));
//data.insert("data2", QJsonValue(QString("val2")));
}
doc.setObject(data);
QMessageBox::warning(0, "__testjson", doc.toJson());
/*
QFile file("c:/temp/test.json");
file.open(QFile::WriteOnly | QFile::Text | QFile::Truncate);
file.write(doc.toJson());
file.close();
*/
}
示例11: fi
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
BookmarksModel* BookmarksModel::NewInstanceFromFile(QString filePath)
{
QFileInfo fi(filePath);
if (fi.exists() & fi.isFile())
{
// Erase the old content
if (self)
{
delete self;
self = NULL;
}
DREAM3DSettings prefs(filePath);
prefs.beginGroup("DockWidgetSettings");
prefs.beginGroup("Bookmarks Dock Widget");
QJsonObject modelObj = prefs.value("Bookmarks Model", QJsonObject());
prefs.endGroup();
prefs.endGroup();
self = BookmarksTreeView::FromJsonObject(modelObj);
}
return self;
}
示例12: QAbstractListModel
DbModel::DbModel(QQuickItem *parent) :
QAbstractListModel(parent),
m_status(Null),
m_schema(QJsonObject()),
m_mapDepth(0),
m_jsonDbPath("")
{
DEBUG;
// QFile db(DBPATH);
// if(!db.open(QIODevice::ReadOnly))
// {
// qDebug() << "db does not exist! creating/copying...";
// QFile file("assets:/qml/MyCollections/db/store.db");
// file.copy(DBPATH);
// } else
// {
// qDebug() << "Successfully opened db, hash is below:";
// QByteArray hashData = QCryptographicHash::hash(db.readAll(),QCryptographicHash::Md5);
// qDebug() << hashData.toHex();
// }
// db.close();
connect(this, SIGNAL(nameChanged(QString)),
this, SLOT(openDatabase()));
connect(this, SIGNAL(schemaChanged(QJsonObject)),
this, SLOT(buildDataTables(QJsonObject)));
}
示例13: testDisconnect
void TestWebChannel::testDisconnect()
{
QWebChannel channel;
channel.connectTo(m_dummyTransport);
channel.disconnectFrom(m_dummyTransport);
m_dummyTransport->emitMessageReceived(QJsonObject());
}
示例14: sharedUser
User *User::remake() {
QJsonObject result = API::sharedAPI()
->sharedAniListAPI()
->get(API::sharedAPI()->sharedAniListAPI()->API_USER)
.object();
if (result == QJsonObject()) return User::sharedUser();
QString profile_image = result.value("image_url_med").toString();
this->setDisplayName(result.value("display_name").toString());
this->setScoreType(result.value("score_type").toInt());
this->setTitleLanguage(result.value("title_language").toString());
this->setAnimeTime(result.value("anime_time").toInt());
this->setCustomLists(
result.value("custom_list_anime").toArray().toVariantList());
this->setNotificationCount(result.value("notifications").toInt());
if (this->profile_image_url != profile_image) {
this->setProfileImageURL(profile_image);
this->loadProfileImage();
}
this->fetchUpdatedList();
return User::sharedUser();
}
示例15: QJsonObject
QJsonObject ModelItem::toJSON() {
QJsonObject root = QJsonObject();
root["t"] = title;
root["s"] = state -> getFuncValue();
root["p"] = path;
if (!info.isEmpty())
root["a"] = info;
if (bpm != 0)
root["m"] = bpm;
if (size != -1)
root["b"] = size;
if (genreID != -1)
root["g"] = genreID;
if (!duration.isEmpty())
root["d"] = duration;
if (!extension.isNull())
root["e"] = extension;
return root;
}