summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-06-05 11:05:24 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-06-05 12:03:40 (GMT)
commit4acabb3abd0ff109b9abeedb6832f5b1c3e0cc4e (patch)
tree76b183192356a216f9084a938d7f3a87a1f4e262 /tests/auto
parentf101435831bb06f342bb0e2241e3011073341617 (diff)
downloadQt-4acabb3abd0ff109b9abeedb6832f5b1c3e0cc4e.zip
Qt-4acabb3abd0ff109b9abeedb6832f5b1c3e0cc4e.tar.gz
Qt-4acabb3abd0ff109b9abeedb6832f5b1c3e0cc4e.tar.bz2
handle qreal properties correctly in the meta-object system
When cross-compiling, it's possible that the size of qreal for moc itself (host platform) is different from the size of qreal on the target platform. Thus, we should not encode the metatype-id of qreal at moc time. Instead, use QMetaType::QReal in the generated code so that the the property flags are only derived at compile time. We also need to support the pesky QT_COORD_TYPE. In this case, qreal can be _any_ type (not just float or double), so we encode the property type as 0 and have a special check in QMetaProperty::type() that resolves the correct type at runtime. Reviewed-by: Simon Hausmann
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qobject/tst_qobject.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp
index 399d021..d76c7d4 100644
--- a/tests/auto/qobject/tst_qobject.cpp
+++ b/tests/auto/qobject/tst_qobject.cpp
@@ -106,6 +106,7 @@ private slots:
void childDeletesItsSibling();
void dynamicProperties();
void floatProperty();
+ void qrealProperty();
void property();
void recursiveSignalEmission();
void blockingQueuedConnection();
@@ -1113,6 +1114,7 @@ class PropertyObject : public QObject
Q_PROPERTY(QVariant variant READ variant WRITE setVariant)
Q_PROPERTY(CustomType* custom READ custom WRITE setCustom)
Q_PROPERTY(float myFloat READ myFloat WRITE setMyFloat)
+ Q_PROPERTY(qreal myQReal READ myQReal WRITE setMyQReal)
public:
enum Alpha {
@@ -1148,6 +1150,9 @@ public:
void setMyFloat(float value) { m_float = value; }
inline float myFloat() const { return m_float; }
+ void setMyQReal(qreal value) { m_qreal = value; }
+ qreal myQReal() const { return m_qreal; }
+
private:
Alpha m_alpha;
Priority m_priority;
@@ -1156,6 +1161,7 @@ private:
QVariant m_variant;
CustomType *m_custom;
float m_float;
+ qreal m_qreal;
};
Q_DECLARE_METATYPE(PropertyObject::Priority)
@@ -2348,6 +2354,27 @@ void tst_QObject::floatProperty()
QVERIFY(qVariantValue<float>(v) == 128.0f);
}
+void tst_QObject::qrealProperty()
+{
+ PropertyObject obj;
+ const int idx = obj.metaObject()->indexOfProperty("myQReal");
+ QVERIFY(idx > 0);
+ QMetaProperty prop = obj.metaObject()->property(idx);
+ QVERIFY(prop.isValid());
+ QVERIFY(prop.type() == uint(QMetaType::type("qreal")));
+ QVERIFY(!prop.write(&obj, QVariant("Hello")));
+
+ QVERIFY(prop.write(&obj, qVariantFromValue(128.0f)));
+ QVariant v = prop.read(&obj);
+ QCOMPARE(v.userType(), qMetaTypeId<qreal>());
+ QVERIFY(qVariantValue<qreal>(v) == 128.0);
+
+ QVERIFY(prop.write(&obj, qVariantFromValue(double(127))));
+ v = prop.read(&obj);
+ QCOMPARE(v.userType(), qMetaTypeId<qreal>());
+ QVERIFY(qVariantValue<qreal>(v) == 127.0);
+}
+
class DynamicPropertyObject : public PropertyObject
{
public: