From b16fab1b636c94cb1fd723f46a1714e010a4dc54 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 27 May 2019 22:03:33 +0200 Subject: Fix deprecation warnings Fix deprecation warnings - replace qFindChild/Children() with QObject::findChild/Children() and replace some 0 with nullptr. Change-Id: If2f01d12fa91d09d98a61f73b0449a6773ac93db Reviewed-by: Friedemann Kleint Reviewed-by: Lars Knoll --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 107 +++++++++++----------- 1 file changed, 52 insertions(+), 55 deletions(-) (limited to 'tests/auto/corelib/kernel/qobject/tst_qobject.cpp') diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index e0394a5d25..f1c4effa95 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -537,91 +536,91 @@ void tst_QObject::findChildren() QObject *op = 0; - op = qFindChild(&o, "o1"); + op = o.findChild("o1"); QCOMPARE(op, &o1); - op = qFindChild(&o, "o2"); + op = o.findChild("o2"); QCOMPARE(op, &o2); - op = qFindChild(&o, "o11"); + op = o.findChild("o11"); QCOMPARE(op, &o11); - op = qFindChild(&o, "o12"); + op = o.findChild("o12"); QCOMPARE(op, &o12); - op = qFindChild(&o, "o111"); + op = o.findChild("o111"); QCOMPARE(op, &o111); - op = qFindChild(&o, "t1"); + op = o.findChild("t1"); QCOMPARE(op, static_cast(&t1)); - op = qFindChild(&o, "t121"); + op = o.findChild("t121"); QCOMPARE(op, static_cast(&t121)); - op = qFindChild(&o, "t1"); + op = o.findChild("t1"); QCOMPARE(op, static_cast(&t1)); - op = qFindChild(&o, "t121"); + op = o.findChild("t121"); QCOMPARE(op, static_cast(&t121)); - op = qFindChild(&o, "o12"); + op = o.findChild("o12"); QCOMPARE(op, static_cast(0)); - op = qFindChild(&o, "o"); + op = o.findChild("o"); QCOMPARE(op, static_cast(0)); - op = qFindChild(&o, "harry"); + op = o.findChild("harry"); QCOMPARE(op, static_cast(0)); - op = qFindChild(&o, "o1"); + op = o.findChild("o1"); QCOMPARE(op, &o1); QList l; QList tl; - l = qFindChildren(&o, "o1"); + l = o.findChildren("o1"); QCOMPARE(l.size(), 1); QCOMPARE(l.at(0), &o1); - l = qFindChildren(&o, "o2"); + l = o.findChildren("o2"); QCOMPARE(l.size(), 1); QCOMPARE(l.at(0), &o2); - l = qFindChildren(&o, "o11"); + l = o.findChildren("o11"); QCOMPARE(l.size(), 1); QCOMPARE(l.at(0), &o11); - l = qFindChildren(&o, "o12"); + l = o.findChildren("o12"); QCOMPARE(l.size(), 1); QCOMPARE(l.at(0), &o12); - l = qFindChildren(&o, "o111"); + l = o.findChildren("o111"); QCOMPARE(l.size(), 1); QCOMPARE(l.at(0), &o111); - l = qFindChildren(&o, "t1"); + l = o.findChildren("t1"); QCOMPARE(l.size(), 1); QCOMPARE(l.at(0), static_cast(&t1)); - l = qFindChildren(&o, "t121"); + l = o.findChildren("t121"); QCOMPARE(l.size(), 1); QCOMPARE(l.at(0), static_cast(&t121)); - tl = qFindChildren(&o, "t1"); + tl = o.findChildren("t1"); QCOMPARE(tl.size(), 1); QCOMPARE(tl.at(0), &t1); - tl = qFindChildren(&o, "t121"); + tl = o.findChildren("t121"); QCOMPARE(tl.size(), 1); QCOMPARE(tl.at(0), &t121); - l = qFindChildren(&o, "o"); + l = o.findChildren("o"); QCOMPARE(l.size(), 0); - l = qFindChildren(&o, "harry"); + l = o.findChildren("harry"); QCOMPARE(l.size(), 0); - tl = qFindChildren(&o, "o12"); + tl = o.findChildren("o12"); QCOMPARE(tl.size(), 0); - l = qFindChildren(&o, "o1"); + l = o.findChildren("o1"); QCOMPARE(l.size(), 1); QCOMPARE(l.at(0), &o1); - l = qFindChildren(&o, QRegExp("o.*")); + l = o.findChildren(QRegularExpression("^o.*$")); QCOMPARE(l.size(), 5); QVERIFY(l.contains(&o1)); QVERIFY(l.contains(&o2)); QVERIFY(l.contains(&o11)); QVERIFY(l.contains(&o12)); QVERIFY(l.contains(&o111)); - l = qFindChildren(&o, QRegExp("t.*")); + l = o.findChildren(QRegularExpression("t.*")); QCOMPARE(l.size(), 2); QVERIFY(l.contains(&t1)); QVERIFY(l.contains(&t121)); - tl = qFindChildren(&o, QRegExp(".*")); + tl = o.findChildren(QRegularExpression("^.*$")); QCOMPARE(tl.size(), 3); QVERIFY(tl.contains(&t1)); QVERIFY(tl.contains(&t121)); - tl = qFindChildren(&o, QRegExp("o.*")); + tl = o.findChildren(QRegularExpression("^o.*$")); QCOMPARE(tl.size(), 0); - l = qFindChildren(&o, QRegExp("harry")); + l = o.findChildren(QRegularExpression("^harry$")); QCOMPARE(l.size(), 0); l = o.findChildren(QRegularExpression("o.*")); @@ -645,18 +644,18 @@ void tst_QObject::findChildren() QCOMPARE(l.size(), 0); // empty and null string check - op = qFindChild(&o); + op = o.findChild(); QCOMPARE(op, &o1); - op = qFindChild(&o, ""); + op = o.findChild(""); QCOMPARE(op, &unnamed); - op = qFindChild(&o, "unnamed"); + op = o.findChild("unnamed"); QCOMPARE(op, static_cast(0)); - l = qFindChildren(&o); + l = o.findChildren(); QCOMPARE(l.size(), 9); - l = qFindChildren(&o, ""); + l = o.findChildren(""); QCOMPARE(l.size(), 2); - l = qFindChildren(&o, "unnamed"); + l = o.findChildren("unnamed"); QCOMPARE(l.size(), 0); tl = o.findChildren("t1"); @@ -724,19 +723,19 @@ void tst_QObject::findChildren() QCOMPARE(l.size(), 1); QCOMPARE(l.at(0), &o1); - l = o.findChildren(QRegExp("o.*"), Qt::FindDirectChildrenOnly); + l = o.findChildren(QRegularExpression("^o.*$"), Qt::FindDirectChildrenOnly); QCOMPARE(l.size(), 2); QVERIFY(l.contains(&o1)); QVERIFY(l.contains(&o2)); - l = o.findChildren(QRegExp("t.*"), Qt::FindDirectChildrenOnly); + l = o.findChildren(QRegularExpression("^t.*$"), Qt::FindDirectChildrenOnly); QCOMPARE(l.size(), 1); QVERIFY(l.contains(&t1)); - tl = o.findChildren(QRegExp(".*"), Qt::FindDirectChildrenOnly); + tl = o.findChildren(QRegularExpression("^.*$"), Qt::FindDirectChildrenOnly); QCOMPARE(tl.size(), 2); QVERIFY(tl.contains(&t1)); - tl = o.findChildren(QRegExp("o.*"), Qt::FindDirectChildrenOnly); + tl = o.findChildren(QRegularExpression("^o.*$"), Qt::FindDirectChildrenOnly); QCOMPARE(tl.size(), 0); - l = o.findChildren(QRegExp("harry"), Qt::FindDirectChildrenOnly); + l = o.findChildren(QRegularExpression("^harry$"), Qt::FindDirectChildrenOnly); QCOMPARE(l.size(), 0); // empty and null string check @@ -1035,18 +1034,16 @@ public Q_SLOTS: void tst_QObject::connectNotify_connectSlotsByName() { ConnectByNameNotifyReceiverObject testObject; - QList senders = - qFindChildren(&testObject); - for (int i = 0; i < senders.size(); ++i) { - ConnectByNameNotifySenderObject *o = senders.at(i); + const QList senders = + testObject.findChildren(); + for (ConnectByNameNotifySenderObject *o : senders) { QVERIFY(o->connectedSignals.isEmpty()); QVERIFY(o->disconnectedSignals.isEmpty()); } QMetaObject::connectSlotsByName(&testObject); - for (int i = 0; i < senders.size(); ++i) { - ConnectByNameNotifySenderObject *o = senders.at(i); + for (ConnectByNameNotifySenderObject *o : senders) { QCOMPARE(o->connectedSignals.size(), 1); QCOMPARE(o->connectedSignals.at(0), QMetaMethod::fromSignal(&ConnectByNameNotifySenderObject::signal1)); QVERIFY(o->disconnectedSignals.isEmpty()); @@ -1631,7 +1628,7 @@ void tst_QObject::thread() QObject object; // thread affinity for objects with no parent should be the // current thread - QVERIFY(object.thread() != 0); + QVERIFY(object.thread() != nullptr); QCOMPARE(object.thread(), currentThread); // children inherit their parent's thread QObject child(&object); @@ -1643,7 +1640,7 @@ void tst_QObject::thread() { TestThread thr; - QVERIFY(thr.thread() != 0); + QVERIFY(thr.thread() != nullptr); QCOMPARE(thr.thread(), currentThread); thr.object = &object; @@ -1802,8 +1799,8 @@ void tst_QObject::moveToThread() QMetaObject::invokeMethod(object, "deleteLater", Qt::QueuedConnection); thread.wait(); - QVERIFY(opointer == 0); - QVERIFY(cpointer == 0); + QVERIFY(opointer == nullptr); + QVERIFY(cpointer == nullptr); } { @@ -2379,7 +2376,7 @@ void tst_QObject::testUserData() for (int i=0; i(my_test_object.userData(id)); - QVERIFY(data != 0); + QVERIFY(data != nullptr); QCOMPARE(data->id, id); } } @@ -3627,7 +3624,7 @@ class OverloadObject : public QObject void sig(int i, int j = 12); void sig(QObject *o, QObject *p, QObject *q = 0, QObject *r = 0) const; void other(int a = 0); - void sig(QObject *o, OverloadObject *p = 0, QObject *q = 0, QObject *r = 0); + void sig(QObject *o, OverloadObject *p = 0, QObject *q = 0, QObject *r = nullptr); void sig(double r = 0.5); public slots: void slo(int i, int j = 43) -- cgit v1.2.3