summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-03-25 13:40:16 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-04-12 21:00:11 +0200
commitd7607a463d0bf51cfa3e77d5e83b1663daf95cfc (patch)
tree9c91665f1fd8bda8fecbcc4e7e64d51ce031e47a
parentf4bf7982a679312146546fabfb086e801c2bbc37 (diff)
QSqlError: Make QSqlErrorPrivate implicitly shared
Make QSqlError implicitly shared and adjust the ctors / assignment operators to be consistent with other implicitly shared Qt classes. Fixes: QTBUG-91912 Change-Id: Ie73292817fd4e7b274a3033a74d62e712a01c2b0 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
-rw-r--r--src/sql/kernel/qsqlerror.cpp25
-rw-r--r--src/sql/kernel/qsqlerror.h10
2 files changed, 12 insertions, 23 deletions
diff --git a/src/sql/kernel/qsqlerror.cpp b/src/sql/kernel/qsqlerror.cpp
index 7483a52e5c..a52f209d53 100644
--- a/src/sql/kernel/qsqlerror.cpp
+++ b/src/sql/kernel/qsqlerror.cpp
@@ -19,7 +19,7 @@ QDebug operator<<(QDebug dbg, const QSqlError &s)
}
#endif
-class QSqlErrorPrivate
+class QSqlErrorPrivate : public QSharedData
{
public:
QString driverError;
@@ -27,7 +27,7 @@ public:
QSqlError::ErrorType errorType;
QString errorCode;
};
-
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QSqlErrorPrivate)
/*!
\class QSqlError
@@ -104,26 +104,15 @@ QSqlError::QSqlError(const QString &driverText, const QString &databaseText,
Creates a copy of \a other.
*/
QSqlError::QSqlError(const QSqlError &other)
- : d(new QSqlErrorPrivate(*other.d))
-{
-}
+ = default;
/*!
Assigns the \a other error's values to this error.
*/
QSqlError &QSqlError::operator=(const QSqlError &other)
-{
- if (&other == this)
- return *this;
- if (d && other.d)
- *d = *other.d;
- else if (d)
- *d = QSqlErrorPrivate();
- else if (other.d)
- d = new QSqlErrorPrivate(*other.d);
- return *this;
-}
+ = default;
+
/*!
Compare the \a other error's type() and nativeErrorCode()
@@ -154,9 +143,7 @@ bool QSqlError::operator!=(const QSqlError &other) const
*/
QSqlError::~QSqlError()
-{
- delete d;
-}
+ = default;
/*!
Returns the text of the error as reported by the driver. This may
diff --git a/src/sql/kernel/qsqlerror.h b/src/sql/kernel/qsqlerror.h
index 2a139d3316..24f2921f5a 100644
--- a/src/sql/kernel/qsqlerror.h
+++ b/src/sql/kernel/qsqlerror.h
@@ -5,11 +5,13 @@
#define QSQLERROR_H
#include <QtSql/qtsqlglobal.h>
+#include <QtCore/qshareddata.h>
#include <QtCore/qstring.h>
QT_BEGIN_NAMESPACE
class QSqlErrorPrivate;
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QSqlErrorPrivate, Q_SQL_EXPORT)
class Q_SQL_EXPORT QSqlError
{
@@ -26,15 +28,15 @@ public:
ErrorType type = NoError,
const QString &errorCode = QString());
QSqlError(const QSqlError &other);
- QSqlError(QSqlError &&other) noexcept : d(other.d) { other.d = nullptr; }
+ QSqlError(QSqlError &&other) noexcept = default;
QSqlError& operator=(const QSqlError &other);
- QSqlError &operator=(QSqlError &&other) noexcept { swap(other); return *this; }
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QSqlError)
~QSqlError();
bool operator==(const QSqlError &other) const;
bool operator!=(const QSqlError &other) const;
- void swap(QSqlError &other) noexcept { qt_ptr_swap(d, other.d); }
+ void swap(QSqlError &other) noexcept { d.swap(other.d); }
QString driverText() const;
QString databaseText() const;
@@ -44,7 +46,7 @@ public:
bool isValid() const;
private:
- QSqlErrorPrivate *d = nullptr;
+ QExplicitlySharedDataPointer<QSqlErrorPrivate> d;
};
Q_DECLARE_SHARED(QSqlError)