IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QMetaMethod Class

The https:// class provides meta-data about a member function.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QMetaMethod Class▲

  • Header: QMetaMethod

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core)

    target_link_libraries(mytarget PRIVATE Qt6::Core)

  • qmake: QT += core

  • Group: QMetaMethod is part of objectmodel

Detailed Description▲

A https:// has a https://(), a https://(), a list of https://() and https://(), a return https://(), a https://(), and an https://() specifier. You can use https://() to invoke the method on an arbitrary https://.

See Also▲

See also https://, https://, https://, https://

Member Type Documentation▲

 

enum QMetaMethod::Access▲

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

Constant

https://::Private

0

https://::Protected

1

https://::Public

2

enum QMetaMethod::MethodType▲

Constant

Value

Description

https://::Method

0

The function is a plain member function.

https://::Signal

1

The function is a signal.

https://::Slot

2

The function is a slot.

https://::Constructor

3

The function is a constructor.

Member Function Documentation▲

 

QMetaMethod::Access QMetaMethod::access() const▲

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

Signals are always public, but you should regard that as an implementation detail. It is almost always a bad idea to emit a signal from outside its class.

See Also▲

See also https://()

[static, since 5.0] QMetaMethod QMetaMethod::fromSignal(PointerToMemberFunction signal)▲

Returns the meta-method that corresponds to the given signal, or an invalid https:// if signal is not a signal of the class.

Example:

 
Sélectionnez
QMetaMethod destroyedSignal = QMetaMethod::fromSignal(&QObject::destroyed);

This function was introduced in Qt 5.0.

bool QMetaMethod::invoke(QObject *object, Qt::ConnectionType connectionType, QGenericReturnArgument returnValue, QGenericArgument val0 = QGenericArgument(nullptr), 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. 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 https://, the member will be invoked immediately.

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

  • If connectionType is https://, 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.

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

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

 
Sélectionnez
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

 
Sélectionnez
QMetaMethod::invoke: Unable to handle unregistered datatype 'MyType'

call https://() 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:

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

https://() 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 https://, one int and one double in the specified order, the call will fail.

this method will not test the validity of the arguments: object must be an instance of the class of the https:// of which this https:// 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▲

See also https://(), https://(), https://(), https://()

bool QMetaMethod::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▲

This function overloads https://().

This overload always invokes this method using the connection type https://.

bool QMetaMethod::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▲

This function overloads https://().

This overload can be used if the return value of the member is of no interest.

bool QMetaMethod::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▲

This function overloads https://().

This overload invokes this method using the connection type https:// and ignores return values.

[since 5.5] bool QMetaMethod::invokeOnGadget(void *gadget, QGenericReturnArgument returnValue, QGenericArgument val0 = QGenericArgument(nullptr), 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 a https://. Returns true if the member could be invoked. Returns false if there is no such member or the parameters did not match.

The pointer gadget must point to an instance of the gadget class.

The invocation is always synchronous.

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

this method will not test the validity of the arguments: gadget must be an instance of the class of the https:// of which this https:// has been constructed with. The arguments must have the same type as the ones expected by the method, else, the behavior is undefined.

This function was introduced in Qt 5.5.

See Also▲

See also https://(), https://(), https://(), https://()

[since 5.5] bool QMetaMethod::invokeOnGadget(void *gadget, 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▲

This is an overloaded function.

This overload invokes this method for a gadget and ignores return values.

This function was introduced in Qt 5.5.

[since 6.2] bool QMetaMethod::isConst() const▲

Returns whether the method is const qualified.

This method might erroneously return false for a const method if it belongs to a library compiled against an older version of Qt.

This function was introduced in Qt 6.2.

[since 5.0] bool QMetaMethod::isValid() const▲

Returns true if this method is valid (can be introspected and invoked), otherwise returns false.

This function was introduced in Qt 5.0.

int QMetaMethod::methodIndex() const▲

Returns this method's index.

[since 5.0] QByteArray QMetaMethod::methodSignature() const▲

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

This function was introduced in Qt 5.0.

See Also▲

See also https://(), https://()

QMetaMethod::MethodType QMetaMethod::methodType() const▲

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

See Also▲

See also https://()

[since 5.0] QByteArray QMetaMethod::name() const▲

Returns the name of this method.

This function was introduced in Qt 5.0.

See Also▲

See also https://(), https://()

[since 5.0] int QMetaMethod::parameterCount() const▲

Returns the number of parameters of this method.

This function was introduced in Qt 5.0.

See Also▲

See also https://(), https://()

[since 6.0] QMetaType QMetaMethod::parameterMetaType(int index) const▲

Returns the metatype of the parameter at the given index.

If the index is smaller than zero or larger than https://(), an invalid https:// is returned.

This function was introduced in Qt 6.0.

See Also▲

See also https://(), https://(), https://

QList<QByteArray> QMetaMethod::parameterNames() const▲

Returns a list of parameter names.

See Also▲

See also https://(), https://()

[since 5.0] int QMetaMethod::parameterType(int index) const▲

Returns the type of the parameter at the given index.

The return value is one of the types that are registered with https://, or https:// if the type is not registered.

This function was introduced in Qt 5.0.

See Also▲

See also https://(), https://(), https://(), https://

[since 6.0] QByteArray QMetaMethod::parameterTypeName(int index) const▲

Returns the name of the type at position index If there is no parameter at index, returns an empty https://

This function was introduced in Qt 6.0.

See Also▲

See also https://()

QList<QByteArray> QMetaMethod::parameterTypes() const▲

Returns a list of parameter types.

See Also▲

See also https://(), https://()

[since 6.0] int QMetaMethod::relativeMethodIndex() const▲

Returns this method's local index inside.

This function was introduced in Qt 6.0.

[since 6.0] QMetaType QMetaMethod::returnMetaType() const▲

Returns the return type of this method.

This function was introduced in Qt 6.0.

See Also▲

See also https://(), https://, https://()

[since 5.0] int QMetaMethod::returnType() const▲

Returns the return type of this method.

The return value is one of the types that are registered with https://, or https:// if the type is not registered.

This function was introduced in Qt 5.0.

See Also▲

See also https://(), https://, https://(), https://()

[since 5.1] int QMetaMethod::revision() const▲

Returns the method revision if one was specified by https://, otherwise returns 0.

This function was introduced in Qt 5.1.

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:

 
Sélectionnez
    // In the class MainWindow declaration
    #ifndef Q_MOC_RUN
    // define the tag text as empty, so the compiler doesn't see it
    #  define MY_CUSTOM_TAG
    #endif
    ...
    private slots:
        MY_CUSTOM_TAG void testFunc();

and the information can be accessed by using:

 
Sélectionnez
    MainWindow win;
    win.show();

    int functionIndex = win.metaObject()-&gt;indexOfSlot("testFunc()");
    QMetaMethod mm = win.metaObject()-&gt;method(functionIndex);
    qDebug() &lt;&lt; mm.tag(); // prints MY_CUSTOM_TAG

For the moment, moc will extract and record all tags, but it will not handle any of them specially. You can use the tags to annotate your methods differently, and treat them according to the specific needs of your application.

Since Qt 5.0, moc expands preprocessor macros, so it is necessary to surround the definition with #ifndef Q_MOC_RUN, as shown in the example above. This was not required in Qt 4. The code as shown above works with Qt 4 too.

const char *QMetaMethod::typeName() const▲

Returns the return type name of this method.

See Also▲

See also https://(), https://()

Related Non-Members▲

 

[since 5.0] bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2)▲

This is an overloaded function.

Returns true if method m1 is not equal to method m2, otherwise returns false.

This function was introduced in Qt 5.0.

[since 5.0] bool operator==(const QMetaMethod &m1, const QMetaMethod &m2)▲

This is an overloaded function.

Returns true if method m1 is equal to method m2, otherwise returns false.

This function was introduced in Qt 5.0.

Macro Documentation▲

 

Q_METAMETHOD_INVOKE_MAX_ARGS▲

Equals maximum number of arguments available for execution of the method via https://()

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+   

Ce document est disponible sous la licence https:// telle que publiée par la Free Software Foundation.