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 /src/corelib/kernel/qobject.h | |
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 'src/corelib/kernel/qobject.h')
-rw-r--r-- | src/corelib/kernel/qobject.h | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index 824a29a5a4..3660a5b3c4 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -43,13 +43,22 @@ struct QDynamicMetaObjectData; typedef QList<QObject*> QObjectList; +#if QT_CORE_REMOVED_SINCE(6, 7) Q_CORE_EXPORT void qt_qFindChildren_helper(const QObject *parent, const QString &name, const QMetaObject &mo, QList<void *> *list, Qt::FindChildOptions options); +#endif +Q_CORE_EXPORT void qt_qFindChildren_helper(const QObject *parent, QAnyStringView name, + const QMetaObject &mo, QList<void *> *list, + Qt::FindChildOptions options); Q_CORE_EXPORT void qt_qFindChildren_helper(const QObject *parent, const QMetaObject &mo, QList<void *> *list, Qt::FindChildOptions options); Q_CORE_EXPORT void qt_qFindChildren_helper(const QObject *parent, const QRegularExpression &re, const QMetaObject &mo, QList<void *> *list, Qt::FindChildOptions options); +#if QT_CORE_REMOVED_SINCE(6, 7) Q_CORE_EXPORT QObject *qt_qFindChild_helper(const QObject *parent, const QString &name, const QMetaObject &mo, Qt::FindChildOptions options); +#endif +Q_CORE_EXPORT QObject *qt_qFindChild_helper(const QObject *parent, QAnyStringView name, + const QMetaObject &mo, Qt::FindChildOptions options); class Q_CORE_EXPORT QObjectData { @@ -131,14 +140,14 @@ public: void killTimer(int id); template<typename T> - inline T findChild(const QString &aName = QString(), Qt::FindChildOptions options = Qt::FindChildrenRecursively) const + T findChild(QAnyStringView aName = {}, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const { typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type ObjType; return static_cast<T>(qt_qFindChild_helper(this, aName, ObjType::staticMetaObject, options)); } template<typename T> - inline QList<T> findChildren(const QString &aName, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const + QList<T> findChildren(QAnyStringView aName, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const { typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type ObjType; QList<T> list; @@ -150,11 +159,7 @@ public: template<typename T> QList<T> findChildren(Qt::FindChildOptions options = Qt::FindChildrenRecursively) const { - typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type ObjType; - QList<T> list; - qt_qFindChildren_helper(this, ObjType::staticMetaObject, - reinterpret_cast<QList<void *> *>(&list), options); - return list; + return findChildren<T>(QAnyStringView{}, options); } #if QT_CONFIG(regularexpression) |