From b480acb3720c0d61c5c69a2b861af63b9d7c9f86 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 9 Apr 2020 16:04:55 +0200 Subject: Allow for private properties to be implemented using QProperty Recently the moc learned that Q_PROPERTY(int x ...) can mean that "x" is implemented as QProperty and then allows installing bindings, etc. - this works by scanning the same class' members. For our own use of QProperty, we need to place the QProperty member itself into the d-pointer to be able to maintain the ability to add new properties without breaking binary compatibility. That however means that moc can't know that a certain property is backed by QProperty - we don't scan the members of the private class. As a workaround, this change enables the syntax where the property type used in Q_PRIVATE_PROPERTY may be wrapped with QProperty. In addition this patch fixes the compilation of such declared properties by ensuring the accessor prefix (t->$accessor) is applied also for the QProperty related meta call variants. Change-Id: I8fbdc49319048b57f4eb0b65b56daba0459e9598 Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/tools/moc/tst_moc.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/auto/tools/moc/tst_moc.cpp') diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index 08dae7f6ca..f3cc21f502 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -1542,6 +1542,7 @@ class PrivatePropertyTest : public QObject Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, QString blub4 MEMBER mBlub NOTIFY blub4Changed) Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, QString blub5 MEMBER mBlub NOTIFY blub5Changed) Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, QString blub6 MEMBER mConst CONSTANT) + Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, QProperty x) class MyDPointer { public: MyDPointer() : mConst("const"), mBar(0), mPlop(0) {} @@ -1555,6 +1556,7 @@ class PrivatePropertyTest : public QObject void setBlub(const QString &value) { mBlub = value; } QString mBlub; const QString mConst; + QProperty x; private: int mBar; int mPlop; @@ -1590,6 +1592,9 @@ void tst_Moc::qprivateproperties() test.setProperty("baz", 4); QCOMPARE(test.property("baz"), QVariant::fromValue(4)); + test.setProperty("x", 100); + QCOMPARE(test.property("x"), QVariant::fromValue(100)); + QVERIFY(test.metaObject()->property(test.metaObject()->indexOfProperty("x")).isQProperty()); } void tst_Moc::warnOnPropertyWithoutREAD() -- cgit v1.2.3