From 5f730041dcb36d95e5e8d453c9b3dc3e3813db60 Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Tue, 12 Mar 2019 00:45:17 +0100 Subject: [PATCH] KDDateTime: added conversion operator to QVariant This prevents implicit conversion to base QDateTime and loss of time-zone information when passing the value as QVariant. Fixes #123. --- doc/CHANGES_1_8.txt | 1 + src/KDSoapClient/KDDateTime.cpp | 5 +++++ src/KDSoapClient/KDDateTime.h | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/doc/CHANGES_1_8.txt b/doc/CHANGES_1_8.txt index 4c523c170..c5a3d82fa 100644 --- a/doc/CHANGES_1_8.txt +++ b/doc/CHANGES_1_8.txt @@ -20,6 +20,7 @@ Client-side: * Rename the missing KDSoapJob::returnHeaders() to KDSoapJob::replyHeaders(), and provide an implementation * Make KDSoapClientInterface::soapVersion() const * Add lastFaultCode() for error handling after sync calls. Same as lastErrorCode() but it returns a QString rather than an int. +* Add conversion operator from KDDateTime to QVariant to void implicit conversion to base QDateTime (github issue #123). Server-side: ============ diff --git a/src/KDSoapClient/KDDateTime.cpp b/src/KDSoapClient/KDDateTime.cpp index ab2b60363..9a4575514 100644 --- a/src/KDSoapClient/KDDateTime.cpp +++ b/src/KDSoapClient/KDDateTime.cpp @@ -57,6 +57,11 @@ KDDateTime::~KDDateTime() { } +KDDateTime::operator QVariant() const +{ + return QVariant::fromValue(*this); +} + QString KDDateTime::timeZone() const { return d->mTimeZone; diff --git a/src/KDSoapClient/KDDateTime.h b/src/KDSoapClient/KDDateTime.h index e432193a6..2fe46b116 100644 --- a/src/KDSoapClient/KDDateTime.h +++ b/src/KDSoapClient/KDDateTime.h @@ -50,6 +50,13 @@ class KDSOAP_EXPORT KDDateTime : public QDateTime KDDateTime &operator=(const KDDateTime &); ~KDDateTime(); + /** + * Converts the KDDateTime to QVariant, to avoid implicit conversion + * to base QDateTime. + * \since 1.8 + */ + operator QVariant() const; + /** * Returns the time zone set by setTimeZone. */