diff options
-rw-r--r-- | src/sql/kernel/qsqlerror.cpp | 25 | ||||
-rw-r--r-- | src/sql/kernel/qsqlerror.h | 10 |
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) |