本文整理汇总了C++中QVariantHash::constFind方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariantHash::constFind方法的具体用法?C++ QVariantHash::constFind怎么用?C++ QVariantHash::constFind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariantHash
的用法示例。
在下文中一共展示了QVariantHash::constFind方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: render
QByteArray ViewJson::render(Context *c) const
{
Q_D(const ViewJson);
QByteArray ret;
QJsonObject obj;
const QVariantHash stash = c->stash();
switch (d->exposeMode) {
case All:
obj = QJsonObject::fromVariantHash(stash);
break;
case String:
{
auto it = stash.constFind(d->exposeKey);
if (it != stash.constEnd()) {
obj.insert(d->exposeKey, QJsonValue::fromVariant(it.value()));
}
break;
}
case StringList:
{
QVariantHash exposedStash;
auto it = stash.constBegin();
while (it != stash.constEnd()) {
const QString key = it.key();
if (d->exposeKeys.contains(key)) {
exposedStash.insertMulti(it.key(), it.value());
}
++it;
}
obj = QJsonObject::fromVariantHash(exposedStash);
break;
}
case RegularExpression:
{
QVariantHash exposedStash;
QRegularExpression re = d->exposeRE; // thread safety
auto it = stash.constBegin();
while (it != stash.constEnd()) {
const QString key = it.key();
if (re.match(key).hasMatch()) {
exposedStash.insertMulti(key, it.value());
}
++it;
}
obj = QJsonObject::fromVariantHash(exposedStash);
break;
}
}
c->response()->setContentType(QStringLiteral("application/json"));
ret = QJsonDocument(obj).toJson(d->format);
return ret;
}
示例2: render
QByteArray ViewEmail::render(Context *c) const
{
Q_D(const ViewEmail);
QVariantHash email = c->stash(d->stashKey).toHash();
if (email.isEmpty()) {
c->error(QStringLiteral("Cannot render template, template name or template stash key not defined"));
return QByteArray();
}
MimeMessage message;
QVariant value;
value = email.value(QStringLiteral("to"));
if (value.type() == QVariant::String && !value.toString().isEmpty()) {
message.addTo(value.toString());
}
value = email.value(QStringLiteral("cc"));
if (value.type() == QVariant::String && !value.toString().isEmpty()) {
message.addCc(value.toString());
}
value = email.value(QStringLiteral("from"));
if (value.type() == QVariant::String && !value.toString().isEmpty()) {
message.setSender(value.toString());
}
value = email.value(QStringLiteral("subject"));
if (value.type() == QVariant::String && !value.toString().isEmpty()) {
message.setSubject(value.toString());
}
QVariant body = email.value(QStringLiteral("body"));
QVariant parts = email.value(QStringLiteral("parts"));
if (body.isNull() && parts.isNull()) {
c->error(QStringLiteral("Can't send email without parts or body, check stash"));
return QByteArray();
}
if (!parts.isNull()) {
const QVariantList partsVariant = parts.toList();
Q_FOREACH (const QVariant &part, partsVariant) {
MimePart *mime = part.value<MimePart*>();
if (mime) {
message.addPart(mime);
} else {
qCCritical(CUTELYST_VIEW_EMAIL) << "Failed to cast MimePart";
}
}
auto contentTypeIt = email.constFind(QStringLiteral("content_type"));
if (contentTypeIt != email.constEnd()
&& !contentTypeIt.value().isNull()
&& !contentTypeIt.value().toString().isEmpty()) {
const QByteArray contentType = contentTypeIt.value().toString().toLatin1();
qCDebug(CUTELYST_VIEW_EMAIL) << "Using specified content_type" << contentType;
message.getContent().setContentType(contentType);
} else if (!d->defaultContentType.isEmpty()) {
qCDebug(CUTELYST_VIEW_EMAIL) << "Using default content_type" << d->defaultContentType;
message.getContent().setContentType(d->defaultContentType);
}
} else {