From 78361ef8e3a78b1db4a393f4760d505761993507 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 9 Feb 2022 16:04:33 -0800 Subject: [PATCH] Qt6: deal with changes from QStringRef to QStringView QStringRef is gone in Qt6 and mostly replaced by QStringView. The one major difference is that direct comparisons with string literals are no longer possible. Thanks to Thiago Macieira for helping me avoid more conditional compilation here. Signed-off-by: Dirk Hohndel --- core/namecmp.h | 16 ++++++++++++++++ core/parse-gpx.cpp | 5 +++-- desktop-widgets/subsurfacewebservices.cpp | 11 ++++++----- 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 core/namecmp.h diff --git a/core/namecmp.h b/core/namecmp.h new file mode 100644 index 000000000..f0781bb50 --- /dev/null +++ b/core/namecmp.h @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef NAMECMP_H +#define NAMECMP_H + +#ifdef __cplusplus + +#include + +// this is annoying Qt5 / Qt6 incompatibility where we can't compare against string literals anymore +static inline int nameCmp(QXmlStreamReader &r, const char * cs) +{ + return r.name().compare(QLatin1String(cs)); +} + +#endif +#endif // NAMECMP_H diff --git a/core/parse-gpx.cpp b/core/parse-gpx.cpp index 11e332091..67feae3c5 100644 --- a/core/parse-gpx.cpp +++ b/core/parse-gpx.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include "core/parse-gpx.h" #include "core/subsurface-time.h" +#include "core/namecmp.h" #include #include @@ -43,7 +44,7 @@ int getCoordsFromGPXFile(struct dive_coords *coords, QString fileName) while (!gpxReader.atEnd()) { gpxReader.readNext(); if (gpxReader.isStartElement()) { - if (gpxReader.name() == "trkpt") { + if (nameCmp(gpxReader, "trkpt") == 0) { trkpt_found = true; line++; foreach (const QXmlStreamAttribute &attr, gpxReader.attributes()) { @@ -53,7 +54,7 @@ int getCoordsFromGPXFile(struct dive_coords *coords, QString fileName) lon = attr.value().toString().toDouble(); } } - if (gpxReader.name() == "time" && trkpt_found) { // Ignore the