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>bb10
parent
f4bf7982a6
commit
d7607a463d
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue