Qt 4.8
Public Types | Public Functions | Properties | Friends | List of all members
QMetaMethod Class Reference

The QMetaMethod class provides meta-data about a member function. More...

#include <qmetaobject.h>

Public Types

enum  Access { Private, Protected, Public }
 This enum describes the access level of a method, following the conventions used in C++. More...
 
enum  Attributes { Compatibility = 0x1, Cloned = 0x2, Scriptable = 0x4 }
 
enum  MethodType { Method, Signal, Slot, Constructor }
 

Public Functions

Access access () const
 Returns the access specification of this method (private, protected, or public). More...
 
int attributes () const
 
const QMetaObjectenclosingMetaObject () const
 
bool invoke (QObject *object, Qt::ConnectionType connectionType, QGenericReturnArgument returnValue, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
 Invokes this method on the object object. More...
 
bool invoke (QObject *object, QGenericReturnArgument returnValue, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
 
bool invoke (QObject *object, Qt::ConnectionType connectionType, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
 
bool invoke (QObject *object, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
 
int methodIndex () const
 Returns this method's index. More...
 
MethodType methodType () const
 Returns the type of this method (signal, slot, or method). More...
 
QList< QByteArrayparameterNames () const
 Returns a list of parameter names. More...
 
QList< QByteArrayparameterTypes () const
 Returns a list of parameter types. More...
 
 QMetaMethod ()
 
int revision () const
 Returns the method revision if one was specified by Q_REVISION, otherwise returns 0. More...
 
const char * signature () const
 Returns the signature of this method (e.g., setValue(double)). More...
 
const char * tag () const
 Returns the tag associated with this method. More...
 
const char * typeName () const
 Returns the return type of this method, or an empty string if the return type is void. More...
 

Properties

uint handle
 
const QMetaObjectmobj
 

Friends

struct QMetaObject
 
struct QMetaObjectPrivate
 
class QObject
 

Detailed Description

The QMetaMethod class provides meta-data about a member function.

A QMetaMethod has a methodType(), a signature(), a list of parameterTypes() and parameterNames(), a return typeName(), a tag(), and an access() specifier. You can use invoke() to invoke the method on an arbitrary QObject.

A method will only be registered with the meta-object system if it is a slot, a signal, or declared with the Q_INVOKABLE macro. Constructors can also be registered with Q_INVOKABLE.

See also
QMetaObject, QMetaEnum, QMetaProperty, {Qt's Property System}

Definition at line 56 of file qmetaobject.h.

Enumerations

◆ Access

This enum describes the access level of a method, following the conventions used in C++.

  • Private
  • Protected
  • Public
Enumerator
Private 
Protected 
Public 

Definition at line 66 of file qmetaobject.h.

◆ Attributes

Warning
This function is not part of the public interface.
  • Compatibility
  • Cloned
  • Scriptable
Enumerator
Compatibility 
Cloned 
Scriptable 

Definition at line 70 of file qmetaobject.h.

◆ MethodType

  • Method The function is a plain member function.
  • Signal The function is a signal.
  • Slot The function is a slot.
  • Constructor The function is a constructor.
Enumerator
Method 
Signal 
Slot 
Constructor 

Definition at line 68 of file qmetaobject.h.

Constructors and Destructors

◆ QMetaMethod()

QMetaMethod::QMetaMethod ( )
inline
Warning
This function is not part of the public interface.

Definition at line 59 of file qmetaobject.h.

59 : mobj(0),handle(0) {}
const QMetaObject * mobj
Definition: qmetaobject.h:139

Functions

◆ access()

QMetaMethod::Access QMetaMethod::access ( ) const

Returns the access specification of this method (private, protected, or public).

Signals are always protected, meaning that you can only emit them from the class or from a subclass.

See also
methodType()

Definition at line 1496 of file qmetaobject.cpp.

Referenced by QAccessibleObjectPrivate::actionList(), QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMetaObject(), QMetaObjectBuilder::addMethod(), QDeclarativePropertyCache::append(), classIDL(), QDeclarativePropertyCache::create(), findSlot(), generateInterfaceXml(), QScript::hasMethodAccess(), and QTest::isValidSlot().

1497 {
1498  if (!mobj)
1499  return Private;
1500  return (QMetaMethod::Access)(mobj->d.data[handle + 4] & AccessMask);
1501 }
Access
This enum describes the access level of a method, following the conventions used in C++...
Definition: qmetaobject.h:66
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:139

◆ attributes()

int QMetaMethod::attributes ( ) const
Warning
This function is not part of the public interface.

Definition at line 1443 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), check_and_warn_compat(), classIDL(), QMetaObject::connectSlotsByName(), findSlot(), generateInterfaceXml(), QScript::QtFunction::mostGeneralMethod(), qax_generateDocumentation(), and QStateMachinePrivate::registerSignalTransition().

1444 {
1445  if (!mobj)
1446  return false;
1447  return ((mobj->d.data[handle + 4])>>4);
1448 }
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:139

◆ enclosingMetaObject()

const QMetaObject * QMetaMethod::enclosingMetaObject ( ) const
inline
Warning
This function is not part of the public interface.

Definition at line 75 of file qmetaobject.h.

Referenced by QMetaObject::connectSlotsByName().

75 { return mobj; }
const QMetaObject * mobj
Definition: qmetaobject.h:139

◆ invoke() [1/4]

Invokes this method on the object object.

Returns true if the member could be invoked. Returns false if there is no such member or the parameters did not match.

The invocation can be either synchronous or asynchronous, depending on the connectionType:

  • If connectionType is Qt::DirectConnection, the member will be invoked immediately.

  • If connectionType is Qt::QueuedConnection, a QEvent will be posted and the member is invoked as soon as the application enters the main event loop.

  • If connectionType is Qt::AutoConnection, the member is invoked synchronously if object lives in the same thread as the caller; otherwise it will invoke the member asynchronously.

The return value of this method call is placed in returnValue. If the invocation is asynchronous, the return value cannot be evaluated. You can pass up to ten arguments (val0, val1, val2, val3, val4, val5, val6, val7, val8, and val9) to this method call.

QGenericArgument and QGenericReturnArgument are internal helper classes. Because signals and slots can be dynamically invoked, you must enclose the arguments using the Q_ARG() and Q_RETURN_ARG() macros. Q_ARG() takes a type name and a const reference of that type; Q_RETURN_ARG() takes a type name and a non-const reference.

To asynchronously invoke the animateClick() slot on a QPushButton:

int methodIndex = pushButton->metaObject()->indexOfMethod("animateClick()");
QMetaMethod method = metaObject->method(methodIndex);
method.invoke(pushButton, Qt::QueuedConnection);

With asynchronous method invocations, the parameters must be of types that are known to Qt's meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes. If you try to use a queued connection and get the error message

QMetaMethod::invoke: Unable to handle unregistered datatype 'MyType'

call qRegisterMetaType() to register the data type before you call QMetaMethod::invoke().

To synchronously invoke the compute(QString, int, double) slot on some arbitrary object obj retrieve its return value:

QString retVal;
QByteArray normalizedSignature = QMetaObject::normalizedSignature("compute(QString, int, double)");
int methodIndex = obj->metaObject()->indexOfMethod(normalizedSignature);
QMetaMethod method = metaObject->method(methodIndex);
method.invoke(obj,
Q_ARG(QString, "sqrt"),
Q_ARG(int, 42),
Q_ARG(double, 9.7));

QMetaObject::normalizedSignature() is used here to ensure that the format of the signature is what invoke() expects. E.g. extra whitespace is removed.

If the "compute" slot does not take exactly one QString, one int and one double in the specified order, the call will fail.

Warning
this method will not test the validity of the arguments: object must be an instance of the class of the QMetaObject of which this QMetaMethod has been constructed with. The arguments must have the same type as the ones expected by the method, else, the behaviour is undefined.
See also
Q_ARG(), Q_RETURN_ARG(), qRegisterMetaType(), QMetaObject::invokeMethod()

Definition at line 1583 of file qmetaobject.cpp.

Referenced by QGraphicsScene::addItem(), QMetaObject::invokeMethod(), QTest::invokeMethod(), QDeclarativeKeysAttached::keyPressed(), and QGraphicsScenePrivate::markDirty().

1596 {
1597  if (!object || !mobj)
1598  return false;
1599 
1600  Q_ASSERT(mobj->cast(object));
1601 
1602  // check return type
1603  if (returnValue.data()) {
1604  const char *retType = typeName();
1605  if (qstrcmp(returnValue.name(), retType) != 0) {
1606  // normalize the return value as well
1607  // the trick here is to make a function signature out of the return type
1608  // so that we can call normalizedSignature() and avoid duplicating code
1609  QByteArray unnormalized;
1610  int len = qstrlen(returnValue.name());
1611 
1612  unnormalized.reserve(len + 3);
1613  unnormalized = "_("; // the function is called "_"
1614  unnormalized.append(returnValue.name());
1615  unnormalized.append(')');
1616 
1617  QByteArray normalized = QMetaObject::normalizedSignature(unnormalized.constData());
1618  normalized.truncate(normalized.length() - 1); // drop the ending ')'
1619 
1620  if (qstrcmp(normalized.constData() + 2, retType) != 0)
1621  return false;
1622  }
1623  }
1624 
1625  // check argument count (we don't allow invoking a method if given too few arguments)
1626  const char *typeNames[] = {
1627  returnValue.name(),
1628  val0.name(),
1629  val1.name(),
1630  val2.name(),
1631  val3.name(),
1632  val4.name(),
1633  val5.name(),
1634  val6.name(),
1635  val7.name(),
1636  val8.name(),
1637  val9.name()
1638  };
1639  int paramCount;
1640  for (paramCount = 1; paramCount < MaximumParamCount; ++paramCount) {
1641  if (qstrlen(typeNames[paramCount]) <= 0)
1642  break;
1643  }
1644  int metaMethodArgumentCount = 0;
1645  {
1646  // based on QMetaObject::parameterNames()
1647  const char *names = mobj->d.stringdata + mobj->d.data[handle + 1];
1648  if (*names == 0) {
1649  // do we have one or zero arguments?
1650  const char *signature = mobj->d.stringdata + mobj->d.data[handle];
1651  while (*signature && *signature != '(')
1652  ++signature;
1653  if (*++signature != ')')
1654  ++metaMethodArgumentCount;
1655  } else {
1656  --names;
1657  do {
1658  ++names;
1659  while (*names && *names != ',')
1660  ++names;
1661  ++metaMethodArgumentCount;
1662  } while (*names);
1663  }
1664  }
1665  if (paramCount <= metaMethodArgumentCount)
1666  return false;
1667 
1668  // check connection type
1669  QThread *currentThread = QThread::currentThread();
1670  QThread *objectThread = object->thread();
1671  if (connectionType == Qt::AutoConnection) {
1672  connectionType = currentThread == objectThread
1675  }
1676 
1677 #ifdef QT_NO_THREAD
1678  if (connectionType == Qt::BlockingQueuedConnection) {
1679  connectionType = Qt::DirectConnection;
1680  }
1681 #endif
1682 
1683  // invoke!
1684  void *param[] = {
1685  returnValue.data(),
1686  val0.data(),
1687  val1.data(),
1688  val2.data(),
1689  val3.data(),
1690  val4.data(),
1691  val5.data(),
1692  val6.data(),
1693  val7.data(),
1694  val8.data(),
1695  val9.data()
1696  };
1697  // recompute the methodIndex by reversing the arithmetic in QMetaObject::property()
1698  int idx_relative = ((handle - priv(mobj->d.data)->methodData) / 5);
1699  int idx_offset = mobj->methodOffset();
1702  ? reinterpret_cast<const QMetaObjectExtraData *>(mobj->d.extradata)->static_metacall : 0;
1703 
1704  if (connectionType == Qt::DirectConnection) {
1705  if (callFunction) {
1706  callFunction(object, QMetaObject::InvokeMetaMethod, idx_relative, param);
1707  return true;
1708  } else {
1709  return QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, idx_relative + idx_offset, param) < 0;
1710  }
1711  } else if (connectionType == Qt::QueuedConnection) {
1712  if (returnValue.data()) {
1713  qWarning("QMetaMethod::invoke: Unable to invoke methods with return values in "
1714  "queued connections");
1715  return false;
1716  }
1717 
1718  int nargs = 1; // include return type
1719  void **args = (void **) qMalloc(paramCount * sizeof(void *));
1720  Q_CHECK_PTR(args);
1721  int *types = (int *) qMalloc(paramCount * sizeof(int));
1722  Q_CHECK_PTR(types);
1723  types[0] = 0; // return type
1724  args[0] = 0;
1725 
1726  for (int i = 1; i < paramCount; ++i) {
1727  types[i] = QMetaType::type(typeNames[i]);
1728  if (types[i]) {
1729  args[i] = QMetaType::construct(types[i], param[i]);
1730  ++nargs;
1731  } else if (param[i]) {
1732  qWarning("QMetaMethod::invoke: Unable to handle unregistered datatype '%s'",
1733  typeNames[i]);
1734  for (int x = 1; x < i; ++x) {
1735  if (types[x] && args[x])
1736  QMetaType::destroy(types[x], args[x]);
1737  }
1738  qFree(types);
1739  qFree(args);
1740  return false;
1741  }
1742  }
1743 
1744  QCoreApplication::postEvent(object, new QMetaCallEvent(idx_offset, idx_relative, callFunction,
1745  0, -1, nargs, types, args));
1746  } else { // blocking queued connection
1747 #ifndef QT_NO_THREAD
1748  if (currentThread == objectThread) {
1749  qWarning("QMetaMethod::invoke: Dead lock detected in "
1750  "BlockingQueuedConnection: Receiver is %s(%p)",
1751  mobj->className(), object);
1752  }
1753 
1754  QSemaphore semaphore;
1755  QCoreApplication::postEvent(object, new QMetaCallEvent(idx_offset, idx_relative, callFunction,
1756  0, -1, 0, 0, param, &semaphore));
1757  semaphore.acquire();
1758 #endif // QT_NO_THREAD
1759  }
1760  return true;
1761 }
void truncate(int pos)
Truncates the byte array at index position pos.
const void * extradata
Definition: qobjectdefs.h:472
void * data() const
Returns the data set in the constructor.
Definition: qobjectdefs.h:261
The QSemaphore class provides a general counting semaphore.
Definition: qsemaphore.h:57
static QByteArray normalizedSignature(const char *method)
Normalizes the signature of the given method.
QByteArray & append(char c)
Appends the character ch to this byte array.
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
static int metacall(QObject *, Call, int, void **)
Q_CORE_EXPORT void qFree(void *ptr)
Definition: qmalloc.cpp:58
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Q_CORE_EXPORT void * qMalloc(size_t size)
Definition: qmalloc.cpp:53
const char * typeName() const
Returns the return type of this method, or an empty string if the return type is void.
const char * stringdata
Definition: qobjectdefs.h:470
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static void * construct(int type, const void *copy=0)
Returns a copy of copy, assuming it is of type type.
Definition: qmetatype.cpp:1042
QObject * cast(QObject *obj) const
Returns obj if object obj inherits from this meta-object; otherwise returns 0.
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
int methodOffset() const
Returns the method offset for this class; i.e.
void(* StaticMetaCallFunction)(QObject *, QMetaObject::Call, int, void **)
Definition: qobject_p.h:113
Q_CORE_EXPORT void qWarning(const char *,...)
static void destroy(int type, void *data)
Destroys the data, assuming it is of the type given.
Definition: qmetatype.cpp:1263
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
const uint * data
Definition: qobjectdefs.h:471
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
uint qstrlen(const char *str)
Definition: qbytearray.h:79
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853
static const struct @32 types[]
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
static const QMetaObjectPrivate * priv(const uint *data)
struct QMetaObject::@38 d
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
const QMetaObject * mobj
Definition: qmetaobject.h:139
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
static const QMetaObjectPrivate * get(const QMetaObject *metaobject)
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59
const char * name() const
Returns the name set in the constructor.
Definition: qobjectdefs.h:262

◆ invoke() [2/4]

Definition at line 90 of file qmetaobject.h.

102  {
103  return invoke(object, Qt::AutoConnection, returnValue,
104  val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
105  }
bool invoke(QObject *object, Qt::ConnectionType connectionType, QGenericReturnArgument returnValue, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
Invokes this method on the object object.

◆ invoke() [3/4]

Definition at line 106 of file qmetaobject.h.

118  {
119  return invoke(object, connectionType, QGenericReturnArgument(),
120  val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
121  }
The QGenericReturnArgument class is an internal helper class for marshalling arguments.
Definition: qobjectdefs.h:269
bool invoke(QObject *object, Qt::ConnectionType connectionType, QGenericReturnArgument returnValue, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
Invokes this method on the object object.

◆ invoke() [4/4]

Definition at line 122 of file qmetaobject.h.

133  {
135  val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
136  }
The QGenericReturnArgument class is an internal helper class for marshalling arguments.
Definition: qobjectdefs.h:269
bool invoke(QObject *object, Qt::ConnectionType connectionType, QGenericReturnArgument returnValue, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
Invokes this method on the object object.

◆ methodIndex()

int QMetaMethod::methodIndex ( ) const

Returns this method's index.

Since
4.6

Definition at line 1458 of file qmetaobject.cpp.

Referenced by QDeclarativeBoundSignal::disconnect(), QDeclarativeBoundSignal::index(), QDeclarativeBoundSignal::init(), and QDeclarativePropertyCache::Data::load().

1459 {
1460  if (!mobj)
1461  return -1;
1462  return ((handle - priv(mobj->d.data)->methodData) / 5) + mobj->methodOffset();
1463 }
int methodOffset() const
Returns the method offset for this class; i.e.
const uint * data
Definition: qobjectdefs.h:471
static const QMetaObjectPrivate * priv(const uint *data)
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:139

◆ methodType()

QMetaMethod::MethodType QMetaMethod::methodType ( ) const

Returns the type of this method (signal, slot, or method).

See also
access()

Definition at line 1508 of file qmetaobject.cpp.

Referenced by QAccessibleObjectPrivate::actionList(), QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMetaObject(), QMetaObjectBuilder::addMethod(), QDeclarativePropertyCache::append(), check_and_warn_compat(), classIDL(), QObject::connect(), QMetaObject::connectSlotsByName(), QObject::disconnect(), QAxBase::dynamicCallHelper(), findSlot(), QScript::functionConnect(), QScript::functionDisconnect(), generateInterfaceXml(), QScript::hasMethodAccess(), QAxServerBase::internalConnect(), QAxBase::internalInvoke(), QAxServerBase::Invoke(), QAxEventSink::Invoke(), QTest::isValidSlot(), QDeclarativePropertyCache::Data::load(), QMetaObjectPrivate::memberIndexes(), QDBusInterfacePrivate::metacall(), QDeclarativeProxyMetaObject::metaCall(), qax_generateDocumentation(), QAxServerBase::qt_metacall(), and QDBusAbstractAdaptor::setAutoRelaySignals().

1509 {
1510  if (!mobj)
1511  return QMetaMethod::Method;
1512  return (QMetaMethod::MethodType)((mobj->d.data[handle + 4] & MethodTypeMask)>>2);
1513 }
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:139

◆ parameterNames()

QList< QByteArray > QMetaMethod::parameterNames ( ) const

Returns a list of parameter names.

See also
parameterTypes(), signature()

Definition at line 1367 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), classIDL(), generateInterfaceXml(), qax_generateDocumentation(), QDeclarativeBoundSignalParameters::QDeclarativeBoundSignalParameters(), QScriptContextInfoPrivate::QScriptContextInfoPrivate(), and QDeclarativeEngineDebugService::setMethodBody().

1368 {
1369  QList<QByteArray> list;
1370  if (!mobj)
1371  return list;
1372  const char *names = mobj->d.stringdata + mobj->d.data[handle + 1];
1373  if (*names == 0) {
1374  // do we have one or zero arguments?
1375  const char *signature = mobj->d.stringdata + mobj->d.data[handle];
1376  while (*signature && *signature != '(')
1377  ++signature;
1378  if (*++signature != ')')
1379  list += QByteArray();
1380  } else {
1381  --names;
1382  do {
1383  const char *begin = ++names;
1384  while (*names && *names != ',')
1385  ++names;
1386  list += QByteArray(begin, names - begin);
1387  } while (*names);
1388  }
1389  return list;
1390 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const char * stringdata
Definition: qobjectdefs.h:470
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:139
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).

◆ parameterTypes()

QList< QByteArray > QMetaMethod::parameterTypes ( ) const

Returns a list of parameter types.

See also
parameterNames(), signature()

Definition at line 1339 of file qmetaobject.cpp.

Referenced by QDeclarativeObjectMethodScriptClass::callOverloaded(), QDeclarativeObjectMethodScriptClass::callPrecise(), QScript::callQtMethod(), classIDL(), QObject::connect(), QScript::QObjectConnectionManager::execute(), QStateMachinePrivate::handleTransitionSignal(), QSignalSpy::initArgs(), QTest::isValidSlot(), QDeclarativePropertyCache::Data::load(), qax_generateDocumentation(), qDBusParametersForMethod(), QDeclarativeBoundSignalParameters::QDeclarativeBoundSignalParameters(), QTest::qSignalDumperCallback(), QDeclarativeBoundSignal::qt_metacall(), and queued_activate().

1340 {
1341  QList<QByteArray> list;
1342  if (!mobj)
1343  return list;
1344  const char *signature = mobj->d.stringdata + mobj->d.data[handle];
1345  while (*signature && *signature != '(')
1346  ++signature;
1347  while (*signature && *signature != ')' && *++signature != ')') {
1348  const char *begin = signature;
1349  int level = 0;
1350  while (*signature && (level > 0 || *signature != ',') && *signature != ')') {
1351  if (*signature == '<')
1352  ++level;
1353  else if (*signature == '>')
1354  --level;
1355  ++signature;
1356  }
1357  list += QByteArray(begin, signature - begin);
1358  }
1359  return list;
1360 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const char * stringdata
Definition: qobjectdefs.h:470
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:139
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).

◆ revision()

int QMetaMethod::revision ( ) const

Returns the method revision if one was specified by Q_REVISION, otherwise returns 0.

Warning
This function is not part of the public interface.

Definition at line 1474 of file qmetaobject.cpp.

Referenced by QDeclarativeTypePrivate::init(), and QDeclarativePropertyCache::Data::load().

1475 {
1476  if (!mobj)
1477  return 0;
1479  int offset = priv(mobj->d.data)->methodData
1480  + priv(mobj->d.data)->methodCount * 5
1481  + (handle - priv(mobj->d.data)->methodData) / 5;
1482  return mobj->d.data[offset];
1483  }
1484  return 0;
1485 }
Access
This enum describes the access level of a method, following the conventions used in C++...
Definition: qmetaobject.h:66
const uint * data
Definition: qobjectdefs.h:471
static const QMetaObjectPrivate * priv(const uint *data)
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:139

◆ signature()

const char * QMetaMethod::signature ( ) const

Returns the signature of this method (e.g., setValue(double)).

See also
parameterTypes(), parameterNames()

Definition at line 1327 of file qmetaobject.cpp.

Referenced by QAccessibleObjectPrivate::actionList(), QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), QMetaObjectBuilder::addProperty(), QScript::QObjectConnectionManager::addSignalHandler(), QDeclarativePropertyCache::append(), QDeclarativeObjectMethodScriptClass::callOverloaded(), QScript::callQtMethod(), QDBusAbstractInterface::callWithArgumentList(), check_and_warn_compat(), classIDL(), QDeclarativeObjectMethodScriptClass::connect(), QObject::connect(), QDeclarativeProperty::connectNotifySignal(), ShaderEffectItem::connectPropertySignals(), QMetaObject::connectSlotsByName(), QDeclarativePropertyCache::create(), QDeclarativeObjectMethodScriptClass::disconnect(), QObject::disconnect(), QObject::dumpObjectInfo(), QAxBase::dynamicCallHelper(), QScript::QObjectConnectionManager::execute(), QDeclarativePropertyPrivate::findSignalByName(), findSlot(), for(), QScript::functionConnect(), QScript::functionDisconnect(), generateInterfaceXml(), QScript::QObjectDelegate::getOwnPropertyNames(), QStateMachinePrivate::handleTransitionSignal(), QDeclarativePropertyPrivate::initProperty(), QAxBase::internalInvoke(), QAxServerBase::Invoke(), QAxEventSink::Invoke(), QTest::isValidSlot(), QTest::memberName(), QScript::methodNameEquals(), QScript::methodNameLength(), QDeclarativePropertyCache::Data::name(), QScript::QtFunction::overloadedIndexes(), qax_generateDocumentation(), QMetaMethod_name(), QTest::qPrintDataTags(), QTest::qPrintTestSlots(), QTest::qSignalDumperCallback(), QTest::qSignalDumperCallbackSlot(), QDeclarativeBoundSignal::qt_metacall(), QAxServerBase::qt_metacall(), QDBusAdaptorConnector::relay(), QScript::QObjectConnectionManager::removeSignalHandler(), QDBusAbstractAdaptor::setAutoRelaySignals(), setupDBusInterface(), and QObjectPrivate::signalSignature().

1328 {
1329  if (!mobj)
1330  return 0;
1331  return mobj->d.stringdata + mobj->d.data[handle];
1332 }
const char * stringdata
Definition: qobjectdefs.h:470
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:139

◆ tag()

const char * QMetaMethod::tag ( ) const

Returns the tag associated with this method.

Tags are special macros recognized by moc that make it possible to add extra information about a method.

Tag information can be added in the following way in the function declaration:

#define THISISTESTTAG // tag text
...
private slots:
THISISTESTTAG void testFunc();

and the information can be accessed by using:

MainWindow win;
win.show();
int functionIndex = win.metaObject()->indexOfSlot("testFunc()");
QMetaMethod mm = metaObject()->method(functionIndex);
qDebug() << mm.tag(); // prints THISISTESTTAG

For the moment, moc doesn't support any special tags.

Definition at line 1434 of file qmetaobject.cpp.

Referenced by QAccessibleObjectPrivate::actionList(), QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), QDBusAbstractInterface::callWithArgumentList(), findSlot(), and generateInterfaceXml().

1435 {
1436  if (!mobj)
1437  return 0;
1438  return mobj->d.stringdata + mobj->d.data[handle + 3];
1439 }
const char * stringdata
Definition: qobjectdefs.h:470
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:139

◆ typeName()

const char * QMetaMethod::typeName ( ) const

Returns the return type of this method, or an empty string if the return type is void.

Definition at line 1397 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addConstructor(), QMetaObjectBuilder::addMethod(), QScript::callQtMethod(), classIDL(), QAxBase::dynamicCallHelper(), findSlot(), generateInterfaceXml(), QAxBase::internalInvoke(), QTest::isValidSlot(), QDeclarativePropertyCache::Data::load(), QDBusInterfacePrivate::metacall(), qax_generateDocumentation(), and QAxServerBase::qt_metacall().

1398 {
1399  if (!mobj)
1400  return 0;
1401  return mobj->d.stringdata + mobj->d.data[handle + 2];
1402 }
const char * stringdata
Definition: qobjectdefs.h:470
const uint * data
Definition: qobjectdefs.h:471
struct QMetaObject::@38 d
const QMetaObject * mobj
Definition: qmetaobject.h:139

Friends and Related Functions

◆ QMetaObject

friend struct QMetaObject
friend

Definition at line 141 of file qmetaobject.h.

◆ QMetaObjectPrivate

friend struct QMetaObjectPrivate
friend

Definition at line 142 of file qmetaobject.h.

◆ QObject

friend class QObject
friend

Definition at line 143 of file qmetaobject.h.

Properties

◆ handle

uint QMetaMethod::handle
private

◆ mobj

const QMetaObject* QMetaMethod::mobj
private

The documentation for this class was generated from the following files: