Make QCursor constructor explicit to prevent comparison of QPixmap
QPixmap doesn't implement operator==, but QCursor had a non-explicit constructor from a QPixmap, which the compiler would use if two pixmaps get compared. Making that QCursor constructor explicit prevents that implicit conversion, at the cost of potential (but trivially resolved) source incompatibility. Also, make QCursor's comparison operators into hidden friends to avoid any other implicit conversions, and allow only QCursor object to be compared. In addition, delete operator== and operator!= in QPixmap so that the compiler generates a useful error message, rather than a screen full of global operator== candidates. Delete these operators in QIcon as well for consistency. Change-Id: I9b3f770da5718360ecc41c35cf327ef4f60d169b Fixes: QTBUG-85993 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
90436e54cc
commit
b39685d4c2
@ -72,6 +72,8 @@ public:
|
||||
{ swap(other); return *this; }
|
||||
inline void swap(QIcon &other) noexcept
|
||||
{ qSwap(d, other.d); }
|
||||
bool operator==(const QIcon &) const = delete;
|
||||
bool operator!=(const QIcon &) const = delete;
|
||||
|
||||
operator QVariant() const;
|
||||
|
||||
|
@ -77,6 +77,8 @@ public:
|
||||
{ qSwap(data, other.data); return *this; }
|
||||
inline void swap(QPixmap &other) noexcept
|
||||
{ qSwap(data, other.data); }
|
||||
bool operator==(const QPixmap &) const = delete;
|
||||
bool operator!=(const QPixmap &) const = delete;
|
||||
|
||||
operator QVariant() const;
|
||||
|
||||
|
@ -83,7 +83,7 @@ public:
|
||||
QCursor();
|
||||
QCursor(Qt::CursorShape shape);
|
||||
QCursor(const QBitmap &bitmap, const QBitmap &mask, int hotX=-1, int hotY=-1);
|
||||
QCursor(const QPixmap &pixmap, int hotX=-1, int hotY=-1);
|
||||
explicit QCursor(const QPixmap &pixmap, int hotX=-1, int hotY=-1);
|
||||
QCursor(const QCursor &cursor);
|
||||
~QCursor();
|
||||
QCursor &operator=(const QCursor &cursor);
|
||||
@ -117,13 +117,11 @@ public:
|
||||
|
||||
private:
|
||||
friend Q_GUI_EXPORT bool operator==(const QCursor &lhs, const QCursor &rhs) noexcept;
|
||||
friend inline bool operator!=(const QCursor &lhs, const QCursor &rhs) noexcept { return !(lhs == rhs); }
|
||||
QCursorData *d;
|
||||
};
|
||||
Q_DECLARE_SHARED(QCursor)
|
||||
|
||||
Q_GUI_EXPORT bool operator==(const QCursor &lhs, const QCursor &rhs) noexcept;
|
||||
inline bool operator!=(const QCursor &lhs, const QCursor &rhs) noexcept { return !(lhs == rhs); }
|
||||
|
||||
/*****************************************************************************
|
||||
QCursor stream functions
|
||||
*****************************************************************************/
|
||||
|
Loading…
x
Reference in New Issue
Block a user