diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-07-12 15:44:36 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-07-12 16:04:20 +0300 |
commit | 86cebd4ccae1d0c5702ad75f1b0fb0d634bb8680 (patch) | |
tree | 2bc9262589b1f47abb0cbdacbce0be13f6b60e89 /platform/qt | |
parent | e197540f9a6a48311eac4d8033fc0abb92b41d16 (diff) | |
download | qtlocation-mapboxgl-86cebd4ccae1d0c5702ad75f1b0fb0d634bb8680.tar.gz |
[core] Report conversion errors using std::string
char* increases the risk of pointing to a invalid reference. Qt had
to use a static variable as retainer to workaround.
Diffstat (limited to 'platform/qt')
-rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 6 | ||||
-rw-r--r-- | platform/qt/src/qt_geojson.hpp | 10 |
2 files changed, 5 insertions, 11 deletions
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 71264faed7..d9eb43cf05 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -628,7 +628,7 @@ void QMapboxGL::addSource(const QString& sourceID, const QVariant& value) Result<std::unique_ptr<Source>> source = convert<std::unique_ptr<Source>>(value, sourceID.toStdString()); if (!source) { - qWarning() << "Unable to add source:" << source.error().message; + qWarning() << "Unable to add source:" << source.error().message.c_str(); return; } @@ -665,7 +665,7 @@ void QMapboxGL::addLayer(const QVariant& value) Result<std::unique_ptr<Layer>> layer = convert<std::unique_ptr<Layer>>(value); if (!layer) { - qWarning() << "Unable to add layer:" << layer.error().message; + qWarning() << "Unable to add layer:" << layer.error().message.c_str(); return; } @@ -692,7 +692,7 @@ void QMapboxGL::setFilter(const QString& layer_, const QVariant& filter_) Result<Filter> converted = convert<Filter>(filter_); if (!converted) { - qWarning() << "Error parsing filter:" << converted.error().message; + qWarning() << "Error parsing filter:" << converted.error().message.c_str(); return; } filter = std::move(*converted); diff --git a/platform/qt/src/qt_geojson.hpp b/platform/qt/src/qt_geojson.hpp index ff7ee2eada..fd2b689fed 100644 --- a/platform/qt/src/qt_geojson.hpp +++ b/platform/qt/src/qt_geojson.hpp @@ -29,22 +29,16 @@ Result<GeoJSON> convertGeoJSON(const QVariant& value) { d.Parse<0>(value.toByteArray().constData()); } - // Needed to keep the error message alive - // when we go out of this scope. - static std::string error; - if (d.HasParseError()) { std::stringstream message; message << d.GetErrorOffset() << " - " << rapidjson::GetParseError_En(d.GetParseError()); - error = message.str(); - return Error { error.c_str() }; + return Error { message.str() }; } conversion::Result<GeoJSON> geoJSON = conversion::convertGeoJSON<JSValue>(d); if (!geoJSON) { - error = geoJSON.error().message; - return Error { error.c_str() }; + return Error { geoJSON.error().message }; } return geoJSON; |