summaryrefslogtreecommitdiffstats
path: root/tests/auto/tools/moc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/tools/moc')
-rw-r--r--tests/auto/tools/moc/allmocs_baseline_in.json20
-rw-r--r--tests/auto/tools/moc/backslash-newlines.h7
-rw-r--r--tests/auto/tools/moc/cxx-attributes.h10
-rw-r--r--tests/auto/tools/moc/forward-declared-param.h2
-rw-r--r--tests/auto/tools/moc/no-keywords.h4
-rw-r--r--tests/auto/tools/moc/pure-virtual-signals.h4
-rw-r--r--tests/auto/tools/moc/single_function_keyword.h6
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp148
8 files changed, 94 insertions, 107 deletions
diff --git a/tests/auto/tools/moc/allmocs_baseline_in.json b/tests/auto/tools/moc/allmocs_baseline_in.json
index 85751845c4..b477aa01f1 100644
--- a/tests/auto/tools/moc/allmocs_baseline_in.json
+++ b/tests/auto/tools/moc/allmocs_baseline_in.json
@@ -1063,7 +1063,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "prop1",
"read": "getProp1",
"required": false,
@@ -1077,7 +1076,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "prop2",
"read": "getProp2",
"required": false,
@@ -1091,7 +1089,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "prop3",
"read": "getProp3",
"required": false,
@@ -1204,7 +1201,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "flags",
"read": "flags",
"required": false,
@@ -1231,7 +1227,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "flags",
"read": "flags",
"required": false,
@@ -1245,7 +1240,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "flagsList",
"read": "flagsList",
"required": false,
@@ -1593,8 +1587,8 @@
"outputRevision": 68
},
{
- "classes": [
- {
+ "classes": [
+ {
"className": "TestPointeeCanBeIncomplete",
"object": true,
"qualifiedClassName": "TestPointeeCanBeIncomplete",
@@ -1787,7 +1781,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "blah",
"read": "blah",
"required": false,
@@ -1840,7 +1833,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "blah",
"read": "blah",
"required": false,
@@ -2016,7 +2008,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "gadgetPoperty",
"read": "gadgetPoperty",
"required": false,
@@ -2029,7 +2020,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "objectPoperty",
"read": "objectPoperty",
"required": false,
@@ -2055,7 +2045,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "nestedGadgetPoperty",
"read": "nestedGadgetPoperty",
"required": false,
@@ -2081,7 +2070,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "nestedObjectPoperty",
"read": "nestedObjectPoperty",
"required": false,
@@ -2215,7 +2203,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "gadgetPoperty",
"read": "gadgetPoperty",
"required": false,
@@ -2228,7 +2215,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "objectPoperty",
"read": "objectPoperty",
"required": false,
@@ -2254,7 +2240,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "nestedGadgetPoperty",
"read": "nestedGadgetPoperty",
"required": false,
@@ -2280,7 +2265,6 @@
"constant": false,
"designable": true,
"final": false,
- "isQProperty": false,
"name": "nestedObjectPoperty",
"read": "nestedObjectPoperty",
"required": false,
diff --git a/tests/auto/tools/moc/backslash-newlines.h b/tests/auto/tools/moc/backslash-newlines.h
index 081d80dc7a..cb2a7f6558 100644
--- a/tests/auto/tools/moc/backslash-newlines.h
+++ b/tests/auto/tools/moc/backslash-newlines.h
@@ -53,4 +53,9 @@ public slots:
#endif // BACKSLASH_NEWLINES_H
-// ends with \\\r should not make moc crash (QTBUG-53441) (no new lines on purpose!!) \ \ No newline at end of file
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_CLANG("-Wcomment")
+
+// ends with \\\r should not make moc crash (QTBUG-53441) (no new lines on purpose!!) \
+
+QT_WARNING_POP
diff --git a/tests/auto/tools/moc/cxx-attributes.h b/tests/auto/tools/moc/cxx-attributes.h
index eff6a3ec41..abd75afe98 100644
--- a/tests/auto/tools/moc/cxx-attributes.h
+++ b/tests/auto/tools/moc/cxx-attributes.h
@@ -31,6 +31,9 @@
#include <QtCore/QObject>
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_CLANG("-Wunknown-attributes")
+
class CppAttribute : public QObject
{
Q_OBJECT
@@ -57,6 +60,8 @@ public slots:
#endif
};
+QT_WARNING_POP
+
#ifdef Q_MOC_RUN
# define TEST_COMPILER_DEPRECATION [[deprecated]]
# define TEST_COMPILER_DEPRECATION_X(x) [[deprecated(x)]]
@@ -65,6 +70,9 @@ public slots:
# define TEST_COMPILER_DEPRECATION_X(x) Q_DECL_ENUMERATOR_DEPRECATED_X(x)
#endif
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
+
namespace TestQNamespaceDeprecated {
Q_NAMESPACE
enum class TestEnum1 {
@@ -100,4 +108,6 @@ namespace TestQNamespaceDeprecated {
Q_FLAG_NS(TestFlag1)
}
+QT_WARNING_POP
+
#endif // CXXATTRIBUTE_H
diff --git a/tests/auto/tools/moc/forward-declared-param.h b/tests/auto/tools/moc/forward-declared-param.h
index 484e546482..8438ca9128 100644
--- a/tests/auto/tools/moc/forward-declared-param.h
+++ b/tests/auto/tools/moc/forward-declared-param.h
@@ -38,6 +38,8 @@ struct ForwardDeclaredParam;
template <typename T> class ForwardDeclaredContainer;
struct FullyDefined {};
+inline size_t qHash(const FullyDefined &, size_t seed = 0) { return seed; }
+inline bool operator==(const FullyDefined &, const FullyDefined &) { return true; }
Q_DECLARE_METATYPE(FullyDefined)
class ForwardDeclaredParamClass : public QObject
diff --git a/tests/auto/tools/moc/no-keywords.h b/tests/auto/tools/moc/no-keywords.h
index ca77056503..cb0bca7a19 100644
--- a/tests/auto/tools/moc/no-keywords.h
+++ b/tests/auto/tools/moc/no-keywords.h
@@ -69,8 +69,8 @@ public Q_SLOTS:
inline void mySlot() { mySignal(); }
private:
- int signals;
- double slots;
+ Q_DECL_UNUSED_MEMBER int signals;
+ Q_DECL_UNUSED_MEMBER double slots;
};
#define signals Q_SIGNALS
diff --git a/tests/auto/tools/moc/pure-virtual-signals.h b/tests/auto/tools/moc/pure-virtual-signals.h
index d514ee8a04..f8b3a80f91 100644
--- a/tests/auto/tools/moc/pure-virtual-signals.h
+++ b/tests/auto/tools/moc/pure-virtual-signals.h
@@ -45,7 +45,7 @@ class PureVirtualSignalsImpl : public PureVirtualSignalsTest
Q_OBJECT
public:
signals:
- void mySignal();
- void mySignal2(int foo);
+ void mySignal() override;
+ void mySignal2(int foo) override;
};
#endif // PURE_VIRTUAL_SIGNALS_H
diff --git a/tests/auto/tools/moc/single_function_keyword.h b/tests/auto/tools/moc/single_function_keyword.h
index ec1a0ac628..6abcc42a04 100644
--- a/tests/auto/tools/moc/single_function_keyword.h
+++ b/tests/auto/tools/moc/single_function_keyword.h
@@ -47,7 +47,10 @@ class SingleFunctionKeywordBeforeInline : public QObject
public:
inline SingleFunctionKeywordBeforeInline() {}
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_CLANG("-Wundefined-inline")
Q_SIGNAL inline void mySignal();
+QT_WARNING_POP
Q_SLOT inline void mySlot() { emit mySignal(); }
};
@@ -58,7 +61,10 @@ class SingleFunctionKeywordAfterInline : public QObject
public:
inline SingleFunctionKeywordAfterInline() {}
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_CLANG("-Wundefined-inline")
inline Q_SIGNAL void mySignal();
+QT_WARNING_POP
inline Q_SLOT void mySlot() { emit mySignal(); }
};
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index c866fcd903..39712c6d22 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -327,9 +327,13 @@ void StructQObject::foo(struct ForwardDeclaredStruct *)
bool field;
};
- struct Inner unusedVariable;
+ Q_DECL_UNUSED_MEMBER struct Inner unusedVariable;
}
+
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_CLANG("-Wignored-qualifiers")
+
class TestClass : public MyNamespace::TestSuperClass, public DONT_CONFUSE_MOC(MyStruct),
public DONT_CONFUSE_MOC_EVEN_MORE(MyStruct2, dummy, ignored)
{
@@ -551,6 +555,8 @@ private slots:
virtual inline void blub2() {}
};
+QT_WARNING_POP
+
class PropertyTestClass : public QObject
{
Q_OBJECT
@@ -766,7 +772,7 @@ private:
void tst_Moc::initTestCase()
{
- QString binpath = QLibraryInfo::location(QLibraryInfo::BinariesPath);
+ QString binpath = QLibraryInfo::path(QLibraryInfo::BinariesPath);
QString qmake = QString("%1/qmake").arg(binpath);
m_moc = QString("%1/moc").arg(binpath);
@@ -1537,7 +1543,6 @@ 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<int> x)
class MyDPointer {
public:
MyDPointer() : mConst("const"), mBar(0), mPlop(0) {}
@@ -1551,7 +1556,6 @@ class PrivatePropertyTest : public QObject
void setBlub(const QString &value) { mBlub = value; }
QString mBlub;
const QString mConst;
- QProperty<int> x;
private:
int mBar;
int mPlop;
@@ -1562,6 +1566,7 @@ public:
int foo() { return mFoo ; }
void setFoo(int value) { mFoo = value; }
MyDPointer *d_func() {return d.data();}
+ const MyDPointer *d_func() const {return d.data();}
signals:
void blub4Changed();
void blub5Changed(const QString &newBlub);
@@ -1586,10 +1591,6 @@ 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()
@@ -1757,6 +1758,8 @@ void tst_Moc::QTBUG5590_dummyProperty()
QCOMPARE(o.value2(), 82);
}
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_CLANG("-Wignored-qualifiers")
class QTBUG7421_ReturnConstTemplate: public QObject
{ Q_OBJECT
public slots:
@@ -1766,7 +1769,7 @@ public slots:
const QString returnConstString(const QString s) { return s; }
QString const returnConstString2( QString const s) { return s; }
};
-
+QT_WARNING_POP
struct science_constant {};
struct science_const {};
@@ -3422,12 +3425,12 @@ void tst_Moc::autoSignalSpyMetaTypeRegistration()
QVERIFY(i > 0);
- QCOMPARE(QMetaType::type("CustomObject12"), (int)QMetaType::UnknownType);
+ QCOMPARE(QMetaType::fromName("CustomObject12").id(), (int)QMetaType::UnknownType);
QSignalSpy spy(&aro, SIGNAL(someSignal(CustomObject12)));
- QVERIFY(QMetaType::type("CustomObject12") != QMetaType::UnknownType);
- QCOMPARE(QMetaType::type("CustomObject12"), qMetaTypeId<CustomObject12>());
+ QVERIFY(QMetaType::fromName("CustomObject12").id() != QMetaType::UnknownType);
+ QCOMPARE(QMetaType::fromName("CustomObject12").id(), qMetaTypeId<CustomObject12>());
}
void tst_Moc::parseDefines()
@@ -4068,15 +4071,16 @@ void tst_Moc::requiredProperties()
class ClassWithQPropertyMembers : public QObject
{
Q_OBJECT
- Q_PROPERTY(int publicProperty NOTIFY publicPropertyChanged)
- Q_PROPERTY(int privateExposedProperty)
+ Q_PROPERTY(int publicProperty MEMBER publicProperty BINDABLE bindablePublicProperty NOTIFY publicPropertyChanged)
+ Q_PROPERTY(int privateExposedProperty MEMBER privateExposedProperty)
public:
signals:
void publicPropertyChanged();
public:
- QNotifiedProperty<int, &ClassWithQPropertyMembers::publicPropertyChanged> publicProperty;
+ QBindable<int> bindablePublicProperty() { return QBindable<int>(&publicProperty); }
+ Q_OBJECT_BINDABLE_PROPERTY(ClassWithQPropertyMembers, int, publicProperty, &ClassWithQPropertyMembers::publicPropertyChanged);
QProperty<int> notExposed;
@@ -4108,7 +4112,7 @@ void tst_Moc::qpropertyMembers()
QSignalSpy publicPropertySpy(&instance, SIGNAL(publicPropertyChanged()));
- instance.publicProperty.setValue(&instance, 100);
+ instance.publicProperty.setValue(100);
QCOMPARE(prop.read(&instance).toInt(), 100);
QCOMPARE(publicPropertySpy.count(), 1);
@@ -4129,19 +4133,20 @@ void tst_Moc::observerMetaCall()
int observerCallCount = 0;
- QProperty<int> dummy;
- auto handler = dummy.onValueChanged([&observerCallCount]() {
+
+ auto observer = [&observerCallCount]() {
++observerCallCount;
- });
+ };
- {
- void *argv[] = { &handler };
- instance.qt_metacall(QMetaObject::RegisterQPropertyObserver, prop.propertyIndex(), argv);
- }
+ auto bindable = prop.bindable(&instance);
+ QVERIFY(bindable.isBindable());
+
+ auto handler = bindable.onValueChanged(observer);
- instance.publicProperty.setValue(&instance, 100);
+ QCOMPARE(observerCallCount, 0);
+ instance.publicProperty.setValue(100);
QCOMPARE(observerCallCount, 1);
- instance.publicProperty.setValue(&instance, 101);
+ instance.publicProperty.setValue(101);
QCOMPARE(observerCallCount, 2);
}
@@ -4161,62 +4166,47 @@ void tst_Moc::setQPRopertyBinding()
return 42;
});
- {
- void *argv[] = { &binding };
- instance.qt_metacall(QMetaObject::SetQPropertyBinding, prop.propertyIndex(), argv);
- }
+ auto bindable = prop.bindable(&instance);
+ QVERIFY(bindable.isBindable());
+ bindable.setBinding(binding);
QCOMPARE(instance.publicProperty.value(), 42);
QVERIFY(bindingCalled); // but now it should've been called :)
}
-
class ClassWithPrivateQPropertyShim :public QObject
{
Q_OBJECT
public:
- Q_PRIVATE_QPROPERTY(d_func(), int, testProperty, setTestProperty, NOTIFY testPropertyChanged)
- Q_PRIVATE_QPROPERTY(d_func(), int, testProperty2, setTestProperty2, NOTIFY false)
- Q_PRIVATE_QPROPERTY(d_func(), int, lazyTestProperty, setLazyTestProperty,
- NOTIFY lazyTestPropertyChanged STORED false)
-
- Q_PRIVATE_QPROPERTIES_BEGIN
- Q_PRIVATE_QPROPERTY_IMPL(testProperty)
- Q_PRIVATE_QPROPERTY_IMPL(testProperty2)
- Q_PRIVATE_QPROPERTY_IMPL(lazyTestProperty)
- Q_PRIVATE_QPROPERTIES_END
+ Q_PROPERTY(int testProperty READ testProperty WRITE setTestProperty BINDABLE bindableTestProperty NOTIFY testPropertyChanged)
+ Q_PROPERTY(int testProperty2 READ testProperty2 WRITE setTestProperty2 BINDABLE bindableTestProperty2)
+ //Q_PROPERTY(d_func(), int, lazyTestProperty, setLazyTestProperty, NOTIFY lazyTestPropertyChanged)
signals:
void testPropertyChanged();
void lazyTestPropertyChanged();
public:
+ int testProperty() const { return priv.testProperty; }
+ void setTestProperty(int val) { priv.testProperty = val; }
+ int testProperty2() const { return priv.testProperty2; }
+ void setTestProperty2(int val) { priv.testProperty2 = val; }
+
+ QBindable<int> bindableTestProperty() { return QBindable<int>(&priv.testProperty); }
+ QBindable<int> bindableTestProperty2() { return QBindable<int>(&priv.testProperty2); }
+
struct Private {
Private(ClassWithPrivateQPropertyShim *pub)
: q(pub)
{}
+ QBindingStorage bindingStorage;
+
ClassWithPrivateQPropertyShim *q = nullptr;
void onTestPropertyChanged() { q->testPropertyChanged(); }
- QNotifiedProperty<int, &Private::onTestPropertyChanged> testProperty;
+ Q_OBJECT_BINDABLE_PROPERTY(Private, int, testProperty, &Private::onTestPropertyChanged);
QProperty<int> testProperty2;
-
- void onLazyTestPropertyChanged() { q->lazyTestPropertyChanged(); }
-
- const QNotifiedProperty<int, &Private::onLazyTestPropertyChanged> *lazyTestProperty() const {
- // Mind that this prevents the property read from being recorded.
- // For real-world use cases some more logic is necessary here.
- return lazyTestPropertyStorage.data();
- }
-
- QNotifiedProperty<int, &Private::onLazyTestPropertyChanged> *lazyTestProperty() {
- if (!lazyTestPropertyStorage)
- lazyTestPropertyStorage.reset(new QNotifiedProperty<int, &Private::onLazyTestPropertyChanged>);
- return lazyTestPropertyStorage.data();
- }
-
- QScopedPointer<QNotifiedProperty<int, &Private::onLazyTestPropertyChanged>> lazyTestPropertyStorage;
};
Private priv{this};
@@ -4224,6 +4214,14 @@ public:
const Private *d_func() const { return &priv; }
};
+inline const QBindingStorage *qGetBindingStorage(const ClassWithPrivateQPropertyShim::Private *o)
+{
+ return &o->bindingStorage;
+}
+inline QBindingStorage *qGetBindingStorage(ClassWithPrivateQPropertyShim::Private *o)
+{
+ return &o->bindingStorage;
+}
void tst_Moc::privateQPropertyShim()
{
@@ -4236,41 +4234,23 @@ void tst_Moc::privateQPropertyShim()
QVERIFY(prop.notifySignal().isValid());
}
- testObject.priv.testProperty.setValue(&testObject.priv, 42);
+ testObject.priv.testProperty.setValue(42);
QCOMPARE(testObject.property("testProperty").toInt(), 42);
// Behave like a QProperty
- QVERIFY(!testObject.testProperty.hasBinding());
- testObject.testProperty.setBinding([]() { return 100; });
- QCOMPARE(testObject.testProperty.value(), 100);
- QVERIFY(testObject.testProperty.hasBinding());
+ QVERIFY(!testObject.bindableTestProperty().hasBinding());
+ testObject.bindableTestProperty().setBinding([]() { return 100; });
+ QCOMPARE(testObject.testProperty(), 100);
+ QVERIFY(testObject.bindableTestProperty().hasBinding());
// Old style setter getters
testObject.setTestProperty(400);
- QVERIFY(!testObject.testProperty.hasBinding());
+ QVERIFY(!testObject.bindableTestProperty().hasBinding());
QCOMPARE(testObject.testProperty(), 400);
- // Created and default-initialized, without nullptr access
- QCOMPARE(testObject.lazyTestProperty(), 0);
-
- // Explicitly set to something
- testObject.priv.lazyTestProperty()->setValue(&testObject.priv, 42);
- QCOMPARE(testObject.property("lazyTestProperty").toInt(), 42);
-
- // Behave like a QProperty
- QVERIFY(!testObject.lazyTestProperty.hasBinding());
- testObject.lazyTestProperty.setBinding([]() { return 100; });
- QCOMPARE(testObject.lazyTestProperty.value(), 100);
- QVERIFY(testObject.lazyTestProperty.hasBinding());
-
- // Old style setter getters
- testObject.setLazyTestProperty(400);
- QVERIFY(!testObject.lazyTestProperty.hasBinding());
- QCOMPARE(testObject.lazyTestProperty(), 400);
-
- // mo generates correct code for plain QProperty in PIMPL
- testObject.testProperty2.setValue(42);
- QCOMPARE(testObject.testProperty2.value(), 42);
+ // moc generates correct code for plain QProperty in PIMPL
+ testObject.setTestProperty2(42);
+ QCOMPARE(testObject.priv.testProperty2.value(), 42);
}
QTEST_MAIN(tst_Moc)