Skip to content

Commit

Permalink
QMetaMethod: Introduce nameView
Browse files Browse the repository at this point in the history
The QBAView returning variant of name. It can avoid the check whether
the meta-object is dynamic, as it doesn't promise to keep the data valid
when the meta-object is gone.

Change-Id: Id1fcf1827a30c5d35ea1f40c8a519b88be43c23b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
  • Loading branch information
Inkane committed Oct 8, 2024
1 parent a6b5df8 commit 9b481a7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/corelib/kernel/qmetaobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,20 @@ QByteArray QMetaMethod::name() const
return stringData(mobj, QMetaMethodPrivate::get(this)->name());
}

/*!
\since 6.9
Returns the name of this method.
The returned QByteArrayView is valid as long as the meta-object of
the class to which the method belongs is valid.
\sa name
*/
QByteArrayView QMetaMethod::nameView() const
{
return QMetaMethodPrivate::get(this)->name();
}

/*!
\since 5.0
Expand Down
1 change: 1 addition & 0 deletions src/corelib/kernel/qmetaobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Q_CORE_EXPORT QMetaMethod

QByteArray methodSignature() const;
QByteArray name() const;
QByteArrayView nameView() const;
const char *typeName() const;
int returnType() const;
QMetaType returnMetaType() const;
Expand Down
1 change: 1 addition & 0 deletions tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ void tst_QMetaMethod::method()

QByteArray computedName = signature.left(signature.indexOf('('));
QCOMPARE(method.name(), computedName);
QCOMPARE_EQ(method.nameView(), method.name());

QCOMPARE(method.tag(), "");
QCOMPARE(method.returnType(), returnType);
Expand Down

0 comments on commit 9b481a7

Please sign in to comment.