Return a JSON string from QML instead of JS object

Idk why QML can't return a JS object, but it can't.  Strings work, so I
use a string.
This commit is contained in:
Zander Otavka 2016-07-19 13:21:08 -07:00
parent d75c2e2a6f
commit acf4539f4f
2 changed files with 7 additions and 9 deletions

View file

@ -265,7 +265,7 @@ ModalWindow {
if (checkBox) { if (checkBox) {
result.checkBox = checkBoxField.enabled ? checkBoxField.checked : null; result.checkBox = checkBoxField.enabled ? checkBoxField.checked : null;
} }
root.result = result; root.result = JSON.stringify(result);
root.selected(root.result); root.selected(root.result);
root.destroy(); root.destroy();
} }

View file

@ -349,14 +349,12 @@ QVariant OffscreenUi::getCustomInfo(const Icon icon, const QString& title, const
} }
QVariant result = DependencyManager::get<OffscreenUi>()->customInputDialog(icon, title, config); QVariant result = DependencyManager::get<OffscreenUi>()->customInputDialog(icon, title, config);
if (ok && result.isValid()) { if (result.isValid()) {
*ok = true; // We get a JSON encoded result, so we unpack it into a QVariant wrapping a QVariantMap
} result = QVariant(QJsonDocument::fromJson(result.toString().toUtf8()).object().toVariantMap());
if (ok) {
// Casts from QJSValue to QVariantMap (not sure how, just copied from http://lists.qt-project.org/pipermail/development/2014-September/018513.html) *ok = true;
Q_ASSERT(!result.isValid() || result.userType() == qMetaTypeId<QJSValue>()); }
if (result.userType() == qMetaTypeId<QJSValue>()) {
result = qvariant_cast<QJSValue>(result).toVariant();
} }
return result; return result;