diff options
| author | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2025-10-11 21:38:20 +0300 |
|---|---|---|
| committer | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2025-10-11 21:38:20 +0300 |
| commit | 65ebb0d489bb91341f7aa0a894497255085b527f (patch) | |
| tree | 3c6b7050b688c3b61657106abf3acfafcc3c16cb /src/plugins/darwin/qdarwinwebview.mm | |
| parent | 6bfd13e7e525e1785441b9d1c28f2206582065d1 (diff) | |
| parent | ff59e23f40555001abcaab698add69255190371b (diff) | |
Merge tag 'v6.5.7-lts' into tqtc/lts-6.5-opensourcev6.5.7-lts-lgpl6.5
Qt 6.5.7-lts release
Conflicts solved:
dependencies.yaml
Change-Id: Ia65320c501127935e4d739b7e4ae739a166caff0
Diffstat (limited to 'src/plugins/darwin/qdarwinwebview.mm')
| -rw-r--r-- | src/plugins/darwin/qdarwinwebview.mm | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/plugins/darwin/qdarwinwebview.mm b/src/plugins/darwin/qdarwinwebview.mm index 4ec9fc1..80b9916 100644 --- a/src/plugins/darwin/qdarwinwebview.mm +++ b/src/plugins/darwin/qdarwinwebview.mm @@ -17,6 +17,8 @@ #include <CoreFoundation/CoreFoundation.h> #include <WebKit/WebKit.h> +#include <QtCore/qjsondocument.h> + #ifdef Q_OS_IOS #import <UIKit/UIKit.h> #import <UIKit/UIGestureRecognizerSubclass.h> @@ -528,7 +530,29 @@ QVariant fromJSValue(id result) if ([result isKindOfClass:[NSDate class]]) return QDateTime::fromNSDate(static_cast<NSDate *>(result)); - // JSValue also supports arrays and dictionaries, but we don't handle that yet + if ([result isKindOfClass:[NSArray class]] + || [result isKindOfClass:[NSDictionary class]]) { + @try { + // Round-trip via JSON, so we don't have to implement conversion + // from NSArray and NSDictionary manually. + + // FIXME: NSJSONSerialization requires that any nested object + // is NSString, NSNumber, NSArray, NSDictionary, or NSNull, so + // nested NSDates are not supported -- meaning we support plain + // NSDate (above), but not in an array or dict. To handle this + // use-case we'd need a manual conversion. + auto jsonData = QByteArray::fromNSData( + [NSJSONSerialization dataWithJSONObject:result options:0 error:nil]); + + QJsonParseError parseError; + auto jsonDocument = QJsonDocument::fromJson(jsonData, &parseError); + if (parseError.error == QJsonParseError::NoError) + return jsonDocument.toVariant(); + } @catch (NSException *) { + return QVariant(); + } + } + return QVariant(); } |
