diff options
author | Rym Bouabid <rym.bouabid@qt.io> | 2023-10-06 18:34:57 +0200 |
---|---|---|
committer | Rym Bouabid <rym.bouabid@qt.io> | 2023-11-22 01:26:46 +0100 |
commit | e608bc019232f6956c4520be1a6103a1845c6991 (patch) | |
tree | 911e3910878529849fa6f6d4d100e166ecba9169 /tests/auto/corelib/kernel/qobject | |
parent | bdd41f491c0f85ae0897a1c7372c5ecda62a5aab (diff) |
QObject: port findChild/ren() to QAnyStringView
Change the object's name type in QObject::findChild/ren() to
QAnyStringView, because they are only used for comparison against
objectName property.
qt_qFindChild{,ren}_helper() functions taking an objectname as
QString have to stay in the ABI as they were exported in inline
methods before Qt 6.7.
Unlike QString, constructing a null QAnyStringView doesn't involve
any code-size overhead. So, get rid of the split in qt_qFindChildren_helper
that was introduced for QString. Remove unneeded
qt_qFindChildren_with_name helper function and qt_qFindChildren_helper
overload without a name.
findChildren(options) method used to call qt_qFindChildren_helper overload.
Instead, call findChildren overload with name argument and pass
QAnyStringView{} as the object name.
[ChangeLog][QtCore][QObject] Ported QObject::findChild/ren() and
their helper functions to QAnyStringView.
Task-number: QTBUG-103986
Change-Id: I68bda0e581f984ae48b7581ad86cc1b95008c1b0
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel/qobject')
-rw-r--r-- | tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index deb8c542dd..33ecb869b3 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -39,6 +39,8 @@ #include <math.h> +using namespace Qt::StringLiterals; + class tst_QObject : public QObject { Q_OBJECT @@ -520,6 +522,10 @@ void tst_QObject::findChildren() QTimer t1(&o); QTimer t121(&o12); QTimer emptyname(&o); + QObject oo; + QObject o21(&oo); + QObject o22(&oo); + QObject o23(&oo); Q_SET_OBJECT_NAME(o); Q_SET_OBJECT_NAME(o1); @@ -530,6 +536,13 @@ void tst_QObject::findChildren() Q_SET_OBJECT_NAME(t1); Q_SET_OBJECT_NAME(t121); emptyname.setObjectName(""); + Q_SET_OBJECT_NAME(oo); + const QUtf8StringView utf8_name = u8"utf8 ⁎ obj"; + o21.setObjectName(utf8_name); + const QStringView utf16_name = u"utf16 ⁎ obj"; + o22.setObjectName(utf16_name); + constexpr QLatin1StringView L1_name("L1 ⁎ obj"); + o23.setObjectName(L1_name); QObject *op = nullptr; @@ -560,6 +573,27 @@ void tst_QObject::findChildren() op = o.findChild<QObject*>("o1"); QCOMPARE(op, &o1); + op = oo.findChild<QObject*>(utf8_name); + QCOMPARE(op, &o21); + op = oo.findChild<QObject*>(utf8_name.chopped(1)); + QCOMPARE(op, nullptr); + const QUtf8StringView utf8_name_with_trailing_data = u8"utf8 ⁎ obj_data"; + op = oo.findChild<QObject*>(utf8_name_with_trailing_data.chopped(5)); + QCOMPARE(op, &o21); + op = oo.findChild<QObject*>(utf16_name); + QCOMPARE(op, &o22); + op = oo.findChild<QObject*>(utf16_name.chopped(1)); + QCOMPARE(op, nullptr); + const QStringView utf16_name_with_trailing_data = u"utf16 ⁎ obj_data"; + op = oo.findChild<QObject*>(utf16_name_with_trailing_data.chopped(5)); + QCOMPARE(op, &o22); + op = oo.findChild<QObject*>(L1_name); + QCOMPARE(op, &o23); + op = oo.findChild<QObject*>(L1_name.chopped(1)); + QCOMPARE(op, nullptr); + op = oo.findChild<QObject*>((L1_name + "_data"_L1).chopped(5)); + QCOMPARE(op, &o23); + QList<QObject*> l; QList<QTimer*> tl; |