diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-20 15:32:40 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-23 10:42:49 +0200 |
commit | 23d30a1863bff48cf0268a7db5f9bb7fc686a8c5 (patch) | |
tree | 627e6b6226683859ed25c70e57e73f22d69f4fe5 | |
parent | 1e521596c103cf6d742e8b73f641b29aa0737b94 (diff) |
GeoJSON: don't crash when operating on empty data
Fix crashes in "geojson_viewer" example when trying to print or store
debug data without loading a file first.
Change-Id: I7b2955d072af8d2a1f39bfca196ffc309e9b4234
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
(cherry picked from commit 7c7248206907bcb0d65a4810ac5e52faf8da4ec8)
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r-- | examples/location/geojson_viewer/main.cpp | 5 | ||||
-rw-r--r-- | src/location/labs/qgeojson.cpp | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/examples/location/geojson_viewer/main.cpp b/examples/location/geojson_viewer/main.cpp index 3995ff08..91c926a0 100644 --- a/examples/location/geojson_viewer/main.cpp +++ b/examples/location/geojson_viewer/main.cpp @@ -158,8 +158,11 @@ public: } features.append(entry); } - if (nodeType.isEmpty()) // Dirty hack to handle (=skip) the first MIV used to process the fictitious list with 1 element + if (nodeType.isEmpty()) { // Dirty hack to handle (=skip) the first MIV used to process the fictitious list with 1 element + if (features.isEmpty()) + return root; return features.first().toMap(); + } root["data"] = features; return root; } diff --git a/src/location/labs/qgeojson.cpp b/src/location/labs/qgeojson.cpp index 99e612d1..423615ad 100644 --- a/src/location/labs/qgeojson.cpp +++ b/src/location/labs/qgeojson.cpp @@ -1236,6 +1236,8 @@ static QString printQvariant(const QVariant v, int tabs = 0) { readable form. */ QString toString(const QVariantList &geoData) { + if (geoData.isEmpty()) + return QString(); return printQvariant(geoData.first(), 0); } |