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


C++ QVariant::toJsonDocument方法代码示例

本文整理汇总了C++中QVariant::toJsonDocument方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::toJsonDocument方法的具体用法?C++ QVariant::toJsonDocument怎么用?C++ QVariant::toJsonDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QVariant的用法示例。


在下文中一共展示了QVariant::toJsonDocument方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: doProcessRequest


//.........这里部分代码省略.........
            {"command/setTorrentsUpLimit", {"torrents", "setUploadLimit", nullptr}},
            {"command/setTorrentsDlLimit", {"torrents", "setDownloadLimit", nullptr}},
            {"command/increasePrio", {"torrents", "increasePrio", nullptr}},
            {"command/decreasePrio", {"torrents", "decreasePrio", nullptr}},
            {"command/topPrio", {"torrents", "topPrio", nullptr}},
            {"command/bottomPrio", {"torrents", "bottomPrio", nullptr}},
            {"command/setLocation", {"torrents", "setLocation", nullptr}},
            {"command/setAutoTMM", {"torrents", "setAutoManagement", nullptr}},
            {"command/setSuperSeeding", {"torrents", "setSuperSeeding", nullptr}},
            {"command/setForceStart", {"torrents", "setForceStart", nullptr}},
            {"command/toggleSequentialDownload", {"torrents", "toggleSequentialDownload", nullptr}},
            {"command/toggleFirstLastPiecePrio", {"torrents", "toggleFirstLastPiecePrio", nullptr}},

            {"query/transferInfo", {"transfer", "info", nullptr}},
            {"command/alternativeSpeedLimitsEnabled", {"transfer", "speedLimitsMode", nullptr}},
            {"command/toggleAlternativeSpeedLimits", {"transfer", "toggleSpeedLimitsMode", nullptr}},
            {"command/getGlobalUpLimit", {"transfer", "uploadLimit", nullptr}},
            {"command/getGlobalDlLimit", {"transfer", "downloadLimit", nullptr}},
            {"command/setGlobalUpLimit", {"transfer", "setUploadLimit", nullptr}},
            {"command/setGlobalDlLimit", {"transfer", "setDownloadLimit", nullptr}}
        };

        const QString legacyAction {match.captured(QLatin1String("action"))};
        const APICompatInfo compatInfo = APICompatMapping.value(legacyAction);

        scope = compatInfo.scope;
        action = compatInfo.action;
        if (compatInfo.convertFunc)
            compatInfo.convertFunc();

        const QString hash {match.captured(QLatin1String("hash"))};
        if (!hash.isEmpty())
            m_params[QLatin1String("hash")] = hash;

        return true;
    };

    if (!findAPICall())
        findLegacyAPICall();

    APIController *controller = m_apiControllers.value(scope);
    if (!controller) {
        if (request().path == QLatin1String("/version/api")) {
            print(QString::number(COMPAT_API_VERSION), Http::CONTENT_TYPE_TXT);
            return;
        }

        if (request().path == QLatin1String("/version/api_min")) {
            print(QString::number(COMPAT_API_VERSION_MIN), Http::CONTENT_TYPE_TXT);
            return;
        }

        if (request().path == QLatin1String("/version/qbittorrent")) {
            print(QString(QBT_VERSION), Http::CONTENT_TYPE_TXT);
            return;
        }

        sendWebUIFile();
    }
    else {
        if (!session() && !isPublicAPI(scope, action))
            throw ForbiddenHTTPError();

        DataMap data;
        for (const Http::UploadedFile &torrent : request().files)
            data[torrent.filename] = torrent.data;

        try {
            const QVariant result = controller->run(action, m_params, data);
            switch (result.userType()) {
            case QMetaType::QString:
                print(result.toString(), Http::CONTENT_TYPE_TXT);
                break;
            case QMetaType::QJsonDocument:
                print(result.toJsonDocument().toJson(QJsonDocument::Compact), Http::CONTENT_TYPE_JSON);
                break;
            default:
                print(result.toString(), Http::CONTENT_TYPE_TXT);
                break;
            }
        }
        catch (const APIError &error) {
            // re-throw as HTTPError
            switch (error.type()) {
            case APIErrorType::AccessDenied:
                throw ForbiddenHTTPError(error.message());
            case APIErrorType::BadData:
                throw UnsupportedMediaTypeHTTPError(error.message());
            case APIErrorType::BadParams:
                throw BadRequestHTTPError(error.message());
            case APIErrorType::Conflict:
                throw ConflictHTTPError(error.message());
            case APIErrorType::NotFound:
                throw NotFoundHTTPError(error.message());
            default:
                Q_ASSERT(false);
            }
        }
    }
}
开发者ID:elFarto,项目名称:qBittorrent,代码行数:101,代码来源:webapplication.cpp


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