当前位置: 首页>>代码示例>>C++>>正文


C++ QJsonObject函数代码示例

本文整理汇总了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));
}
开发者ID:softnhard,项目名称:QJSON,代码行数:12,代码来源:qjsonvalue.cpp

示例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();
    }
}
开发者ID:yguimaraes,项目名称:pfc_botnets,代码行数:29,代码来源:logselectorform.cpp

示例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();
}
开发者ID:ghjinlei,项目名称:qt5,代码行数:17,代码来源:qjsondocument.cpp

示例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;
}
开发者ID:2gis,项目名称:2gisqt5android,代码行数:60,代码来源:qjsonobject.cpp

示例5: jsonDir

QJsonObject DCMotor::getDirectionJson()
{
    QJsonValue jsonDir(dirn);
    return QJsonObject({
                           QPair<QString, QJsonValue>(directionKey, jsonDir)
                       });
}
开发者ID:rCorvidae,项目名称:StepperAndDcController,代码行数:7,代码来源:dcmotor.cpp

示例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));
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:12,代码来源:qjsonvalue.cpp

示例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();
}
开发者ID:Martchus,项目名称:videodownloader,代码行数:27,代码来源:utils.cpp

示例8: jsonPWM

QJsonObject DCMotor::getPwmJson()
{
    QJsonValue jsonPWM(pwmValue);
    return QJsonObject({
                           QPair<QString, QJsonValue>(pwmKey, jsonPWM)
                       });
}
开发者ID:rCorvidae,项目名称:StepperAndDcController,代码行数:7,代码来源:dcmotor.cpp

示例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;
}
开发者ID:agunnarsson,项目名称:qtlocation,代码行数:32,代码来源:qplacemanagerengine_nokiav2.cpp

示例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();
    */
}
开发者ID:privet56,项目名称:qWebTest,代码行数:35,代码来源:collectmailsesb.cpp

示例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;
}
开发者ID:kglowins,项目名称:DREAM3D,代码行数:28,代码来源:BookmarksModel.cpp

示例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)));
}
开发者ID:ndesai,项目名称:pioneer-av-remote,代码行数:29,代码来源:dbmodel.cpp

示例13: testDisconnect

void TestWebChannel::testDisconnect()
{
    QWebChannel channel;
    channel.connectTo(m_dummyTransport);
    channel.disconnectFrom(m_dummyTransport);
    m_dummyTransport->emitMessageReceived(QJsonObject());
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:7,代码来源:tst_webchannel.cpp

示例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();
}
开发者ID:KasaiDot,项目名称:Shinjiru,代码行数:27,代码来源:user.cpp

示例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;
}
开发者ID:jeyboy,项目名称:palyo2,代码行数:27,代码来源:model_item.cpp


注:本文中的QJsonObject函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。