Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
src_corelib_kernel_qmetaobject.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4
6{
7
9class MyClass : public QObject
10{
12 Q_CLASSINFO("author", "Sabrina Schweinsteiger")
13 Q_CLASSINFO("url", "http://doc.moosesoft.co.uk/1.0/")
14
15public:
16 ...
17};
19
20
22QByteArray normType = QMetaObject::normalizedType(" int const *");
23// normType is now "const int*"
25
26
28QMetaObject::invokeMethod(thread, "quit",
31
32
34QMetaObject::invokeMethod: Unable to handle unregistered datatype 'MyType'
36
38QString retVal;
40 qReturnArg(retVal),
41 QString("sqrt"), 42, 9.7);
43
44
46QString retVal;
48 qReturnArg(retVal),
49 QStringView("sqrt"), qsizetype(42), 9.7f);
51
52
54QString retVal;
56 Q_RETURN_ARG(QString, retVal),
57 Q_ARG(QString, "sqrt"),
58 Q_ARG(int, 42),
59 Q_ARG(double, 9.7));
61
62
64class MyClass
65{
67 Q_CLASSINFO("author", "Sabrina Schweinsteiger")
68 Q_CLASSINFO("url", "http://doc.moosesoft.co.uk/1.0/")
69
70public:
71 ...
72};
74
75
77const QMetaObject* metaObject = obj->metaObject();
79for(int i = metaObject->propertyOffset(); i < metaObject->propertyCount(); ++i)
80 properties << QString::fromLatin1(metaObject->property(i).name());
82
83
85const QMetaObject* metaObject = obj->metaObject();
87for(int i = metaObject->methodOffset(); i < metaObject->methodCount(); ++i)
88 methods << QString::fromLatin1(metaObject->method(i).methodSignature());
90
92int methodIndex = pushButton->metaObject()->indexOfMethod("animateClick()");
93QMetaMethod method = metaObject->method(methodIndex);
96
98QMetaMethod::invoke: Unable to handle unregistered datatype 'MyType'
100
102QString retVal;
103QByteArray normalizedSignature = QMetaObject::normalizedSignature("compute(QString, int, double)");
104int methodIndex = obj->metaObject()->indexOfMethod(normalizedSignature);
105QMetaMethod method = obj->metaObject()->method(methodIndex);
107 QString("sqrt"), 42, 9.7);
109
111QString retVal;
112QByteArray normalizedSignature = QMetaObject::normalizedSignature("compute(QByteArray, qint64, long double)");
113int methodIndex = obj->metaObject()->indexOfMethod(normalizedSignature);
114QMetaMethod method = obj->metaObject()->method(methodIndex);
116 QByteArray("sqrt"), qint64(42), 9.7L);
118
120QString retVal;
121QByteArray normalizedSignature = QMetaObject::normalizedSignature("compute(QString, int, double)");
122int methodIndex = obj->metaObject()->indexOfMethod(normalizedSignature);
123QMetaMethod method = obj->metaObject()->method(methodIndex);
124method.invoke(obj,
126 Q_RETURN_ARG(QString, retVal),
127 Q_ARG(QString, "sqrt"),
128 Q_ARG(int, 42),
129 Q_ARG(double, 9.7));
131
135
137 // In the class MainWindow declaration
138 #ifndef Q_MOC_RUN
139 // define the tag text as empty, so the compiler doesn't see it
140 # define MY_CUSTOM_TAG
141 #endif
142 ...
143 private slots:
144 MY_CUSTOM_TAG void testFunc();
146
149 win.show();
150
151 int functionIndex = win.metaObject()->indexOfSlot("testFunc()");
152 QMetaMethod mm = win.metaObject()->method(functionIndex);
153 qDebug() << mm.tag(); // prints MY_CUSTOM_TAG
155}
static JNINativeMethod methods[]
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qmetaobject.h:19
static QMetaMethod fromSignal(PointerToMemberFunction signal)
bool 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
\obsolete [6.5] Please use the variadic overload of this function
const char * tag() const
Returns the tag associated with this method.
\inmodule QtCore
Definition qobject.h:103
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
\inmodule QtCore
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7875
@ QueuedConnection
@ DirectConnection
static const QCssKnownValue properties[NumProperties - 1]
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char * method
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
#define qDebug
[1]
Definition qlogging.h:164
#define Q_RETURN_ARG(Type, data)
Definition qobjectdefs.h:64
void qReturnArg(const T &&)=delete
#define Q_ARG(Type, data)
Definition qobjectdefs.h:63
GLuint64 GLenum void * handle
GLhandleARB obj
[2]
#define Q_OBJECT
#define Q_CLASSINFO(name, value)
#define slots
ptrdiff_t qsizetype
Definition qtypes.h:165
long long qint64
Definition qtypes.h:60
QWidget * win
Definition settings.cpp:6
#define MY_CUSTOM_TAG
QPushButton * pushButton
obj metaObject() -> className()
\inmodule QtCore
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, 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())
\threadsafe This is an overloaded member function, provided for convenience. It differs from the abov...
static QByteArray normalizedSignature(const char *method)
Normalizes the signature of the given method.
static QByteArray normalizedType(const char *type)