summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2012-09-28 17:22:21 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-10 08:45:22 +0200
commit43325a23f35bce7eddfb2e74d2a65d381b1c6aa0 (patch)
tree6e8916c1cc062b54f7883679e03ab6fd52648ea5 /src/corelib/kernel
parent05541111ae1cf46ef934a287e89cebe08f175b99 (diff)
Delete the QVariant ctors taking global Qt enum values.
They have unexpected results in Qt 5 (the Qt::GlobalColor one works as expected in Qt 4, but was removed in Qt 5): QVariant v = QVariant(Qt::red); qDebug() << v; // QVariant(int, 7) v = Qt::red; qDebug() << v; // QVariant(int, 7) The correct way is to use: QVariant v = QVariant::fromValue(QColor(Qt::red)); The deleted constructors are the ones for which there is a class with an implicit constructor taking the enum, and that class is a built-in metatype. QLocale::Language and QKeySequence::StandardKey would also fit the description, but I can't include the header for QKeySequence as it is in QtGui, and I don't want to include the qlocale header in qvariant.h. Putting a QLocale::Language is probably very uncommon anyway. The QTextFormat test is doing the wrong thing, but the result isn't being tested. Added new tests which fail before the patch. Change-Id: Ia38a0784990f4d40ff7457a86daf58aabd4964eb Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qvariant.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index 9e6de43823..86b43cf69a 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -461,6 +461,16 @@ private:
// want QVariant(QMetaType::String) to compile and falsely be an
// int variant, so delete this constructor:
QVariant(QMetaType::Type) Q_DECL_EQ_DELETE;
+
+ // These constructors don't create QVariants of the type associcated
+ // with the enum, as expected, but they would create a QVariant of
+ // type int with the value of the enum value.
+ // Use QVariant v = QColor(Qt::red) instead of QVariant v = Qt::red for
+ // example.
+ QVariant(Qt::GlobalColor) Q_DECL_EQ_DELETE;
+ QVariant(Qt::BrushStyle) Q_DECL_EQ_DELETE;
+ QVariant(Qt::PenStyle) Q_DECL_EQ_DELETE;
+ QVariant(Qt::CursorShape) Q_DECL_EQ_DELETE;
#ifdef QT_NO_CAST_FROM_ASCII
// force compile error when implicit conversion is not wanted
inline QVariant(const char *) Q_DECL_EQ_DELETE;