108 Q_PROPERTY(QString objectName READ objectName WRITE setObjectName NOTIFY objectNameChanged
109 BINDABLE bindableObjectName)
110 Q_DECLARE_PRIVATE(QObject)
113 Q_INVOKABLE
explicit QObject(QObject *parent =
nullptr);
116 virtual bool event(QEvent *event);
117 virtual bool eventFilter(QObject *watched, QEvent *event);
119#if defined(QT_NO_TRANSLATION) || defined(Q_QDOC)
120 static QString tr(
const char *sourceText,
const char * =
nullptr,
int = -1)
121 {
return QString::fromUtf8(sourceText); }
124 QString objectName()
const;
125#if QT_CORE_REMOVED_SINCE(6
, 4
)
126 void setObjectName(
const QString &name);
129 void setObjectName(
const QString &name) { doSetObjectName(name); }
130 void setObjectName(QAnyStringView name);
131 QBindable<QString> bindableObjectName();
133 inline bool isWidgetType()
const {
return d_ptr->isWidget; }
134 inline bool isWindowType()
const {
return d_ptr->isWindow; }
135 inline bool isQuickItemType()
const {
return d_ptr->isQuickItem; }
136 bool isQmlObjectType()
const;
138 inline bool signalsBlocked()
const noexcept {
return d_ptr->blockSig; }
139 bool blockSignals(
bool b)
noexcept;
141 QThread *thread()
const;
142#if QT_CORE_REMOVED_SINCE(6
, 7
)
143 void moveToThread(QThread *thread);
145 bool moveToThread(QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL);
147 int startTimer(
int interval, Qt::TimerType timerType = Qt::CoarseTimer);
149#if QT_CORE_REMOVED_SINCE(6
, 8
)
150 int startTimer(std::chrono::milliseconds time, Qt::TimerType timerType = Qt::CoarseTimer);
152 int startTimer(std::chrono::nanoseconds time, Qt::TimerType timerType = Qt::CoarseTimer);
154 void killTimer(
int id);
155 void killTimer(Qt::TimerId id);
158 T findChild(QAnyStringView aName, Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
160 typedef typename std::remove_cv<
typename std::remove_pointer<T>::type>::type ObjType;
161 static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
162 "No Q_OBJECT in the class passed to QObject::findChild");
163 return static_cast<T>(qt_qFindChild_helper(
this, aName, ObjType::staticMetaObject, options));
167 QList<T> findChildren(QAnyStringView aName, Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
169 typedef typename std::remove_cv<
typename std::remove_pointer<T>::type>::type ObjType;
170 static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
171 "No Q_OBJECT in the class passed to QObject::findChildren");
173 qt_qFindChildren_helper(
this, aName, ObjType::staticMetaObject,
174 reinterpret_cast<QList<
void *> *>(&list), options);
179 T findChild(Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
181 return findChild<T>({}, options);
185 QList<T> findChildren(Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
187 return findChildren<T>(QAnyStringView{}, options);
190#if QT_CONFIG(regularexpression)
192 inline QList<T> findChildren(
const QRegularExpression &re, Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
194 typedef typename std::remove_cv<
typename std::remove_pointer<T>::type>::type ObjType;
195 static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
196 "No Q_OBJECT in the class passed to QObject::findChildren");
198 qt_qFindChildren_helper(
this, re, ObjType::staticMetaObject,
199 reinterpret_cast<QList<
void *> *>(&list), options);
204 inline const QObjectList &children()
const {
return d_ptr->children; }
206 void setParent(QObject *parent);
207 void installEventFilter(QObject *filterObj);
208 void removeEventFilter(QObject *obj);
210 static QMetaObject::Connection connect(
const QObject *sender,
const char *signal,
211 const QObject *receiver,
const char *member, Qt::ConnectionType = Qt::AutoConnection);
213 static QMetaObject::Connection connect(
const QObject *sender,
const QMetaMethod &signal,
214 const QObject *receiver,
const QMetaMethod &method,
215 Qt::ConnectionType type = Qt::AutoConnection);
217 inline QMetaObject::Connection connect(
const QObject *sender,
const char *signal,
218 const char *member, Qt::ConnectionType type = Qt::AutoConnection)
const;
221 template<
typename PointerToMemberFunction>
222 static QMetaObject::Connection connect(
const QObject *sender, PointerToMemberFunction signal,
const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type = Qt::AutoConnection);
223 template<
typename PointerToMemberFunction,
typename Functor>
224 static QMetaObject::Connection connect(
const QObject *sender, PointerToMemberFunction signal, Functor functor);
225 template<
typename PointerToMemberFunction,
typename Functor>
226 static QMetaObject::Connection connect(
const QObject *sender, PointerToMemberFunction signal,
const QObject *context, Functor functor, Qt::ConnectionType type = Qt::AutoConnection);
229 template <
typename Func1,
typename Func2>
230 static inline QMetaObject::Connection
231 connect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
232 const typename QtPrivate::ContextTypeForFunctor<Func2>::ContextType *context, Func2 &&slot,
233 Qt::ConnectionType type = Qt::AutoConnection)
235 typedef QtPrivate::FunctionPointer<Func1> SignalType;
236 typedef QtPrivate::FunctionPointer<std::decay_t<Func2>> SlotType;
238 if constexpr (SlotType::ArgumentCount != -1) {
239 static_assert((QtPrivate::AreArgumentsCompatible<
typename SlotType::ReturnType,
typename SignalType::ReturnType>::value),
240 "Return type of the slot is not compatible with the return type of the signal.");
242 constexpr int FunctorArgumentCount = QtPrivate::ComputeFunctorArgumentCount<std::decay_t<Func2>,
typename SignalType::Arguments>::Value;
244 constexpr int SlotArgumentCount = (FunctorArgumentCount >= 0) ? FunctorArgumentCount : 0;
245 typedef typename QtPrivate::FunctorReturnType<std::decay_t<Func2>,
typename QtPrivate::List_Left<
typename SignalType::Arguments, SlotArgumentCount>::Value>::type SlotReturnType;
247 static_assert((QtPrivate::AreArgumentsCompatible<SlotReturnType,
typename SignalType::ReturnType>::value),
248 "Return type of the slot is not compatible with the return type of the signal.");
251 static_assert(QtPrivate::HasQ_OBJECT_Macro<
typename SignalType::Object>::Value,
252 "No Q_OBJECT in the class with the signal");
255 static_assert(
int(SignalType::ArgumentCount) >=
int(SlotType::ArgumentCount),
256 "The slot requires more arguments than the signal provides.");
258 const int *types =
nullptr;
259 if (type == Qt::QueuedConnection || type == Qt::BlockingQueuedConnection)
260 types = QtPrivate::ConnectionTypes<
typename SignalType::Arguments>::types();
262 void **pSlot =
nullptr;
263 if constexpr (std::is_member_function_pointer_v<std::decay_t<Func2>>) {
264 pSlot =
const_cast<
void **>(
reinterpret_cast<
void *
const *>(&slot));
266 Q_ASSERT_X((type & Qt::UniqueConnection) == 0,
"",
267 "QObject::connect: Unique connection requires the slot to be a pointer to "
268 "a member function of a QObject subclass.");
271 return connectImpl(sender,
reinterpret_cast<
void **>(&signal), context, pSlot,
272 QtPrivate::makeCallableObject<Func1>(std::forward<Func2>(slot)),
273 type, types, &SignalType::Object::staticMetaObject);
276#ifndef QT_NO_CONTEXTLESS_CONNECT
278 template <
typename Func1,
typename Func2>
279 static inline QMetaObject::Connection
280 connect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 &&slot)
282 return connect(sender, signal, sender, std::forward<Func2>(slot), Qt::DirectConnection);
287 static bool disconnect(
const QObject *sender,
const char *signal,
288 const QObject *receiver,
const char *member);
289 static bool disconnect(
const QObject *sender,
const QMetaMethod &signal,
290 const QObject *receiver,
const QMetaMethod &member);
291 inline bool disconnect(
const char *signal =
nullptr,
292 const QObject *receiver =
nullptr,
const char *member =
nullptr)
const
293 {
return disconnect(
this, signal, receiver, member); }
294 inline bool disconnect(
const QObject *receiver,
const char *member =
nullptr)
const
295 {
return disconnect(
this,
nullptr, receiver, member); }
296 static bool disconnect(
const QMetaObject::Connection &);
299 template<
typename PointerToMemberFunction>
300 static bool disconnect(
const QObject *sender, PointerToMemberFunction signal,
const QObject *receiver, PointerToMemberFunction method);
302 template <
typename Func1,
typename Func2>
303 static inline bool disconnect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
304 const typename QtPrivate::FunctionPointer<Func2>::Object *receiver, Func2 slot)
306 typedef QtPrivate::FunctionPointer<Func1> SignalType;
307 typedef QtPrivate::FunctionPointer<Func2> SlotType;
309 static_assert(QtPrivate::HasQ_OBJECT_Macro<
typename SignalType::Object>::Value,
310 "No Q_OBJECT in the class with the signal");
313 static_assert((QtPrivate::CheckCompatibleArguments<
typename SignalType::Arguments,
typename SlotType::Arguments>::value),
314 "Signal and slot arguments are not compatible.");
316 return disconnectImpl(sender,
reinterpret_cast<
void **>(&signal), receiver,
reinterpret_cast<
void **>(&slot),
317 &SignalType::Object::staticMetaObject);
319 template <
typename Func1>
320 static inline bool disconnect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
321 const QObject *receiver,
void **zero)
327 typedef QtPrivate::FunctionPointer<Func1> SignalType;
328 return disconnectImpl(sender,
reinterpret_cast<
void **>(&signal), receiver, zero,
329 &SignalType::Object::staticMetaObject);
333 void dumpObjectTree()
const;
334 void dumpObjectInfo()
const;
336 QT_CORE_INLINE_SINCE(6, 6)
337 bool setProperty(
const char *name,
const QVariant &value);
338 inline bool setProperty(
const char *name, QVariant &&value);
339 QVariant property(
const char *name)
const;
340 QList<QByteArray> dynamicPropertyNames()
const;
341 QBindingStorage *bindingStorage() {
return &d_ptr->bindingStorage; }
342 const QBindingStorage *bindingStorage()
const {
return &d_ptr->bindingStorage; }
345 void destroyed(QObject * =
nullptr);
346 void objectNameChanged(
const QString &objectName, QPrivateSignal);
349 inline QObject *parent()
const {
return d_ptr->parent; }
351 inline bool inherits(
const char *classname)
const
353 return const_cast<QObject *>(
this)->qt_metacast(classname) !=
nullptr;
360 QObject *sender()
const;
361 int senderSignalIndex()
const;
362 int receivers(
const char *signal)
const;
363 bool isSignalConnected(
const QMetaMethod &signal)
const;
365 virtual void timerEvent(QTimerEvent *event);
366 virtual void childEvent(QChildEvent *event);
367 virtual void customEvent(QEvent *event);
369 virtual void connectNotify(
const QMetaMethod &signal);
370 virtual void disconnectNotify(
const QMetaMethod &signal);
373 QObject(QObjectPrivate &dd, QObject *parent =
nullptr);
376 QScopedPointer<QObjectData> d_ptr;
378 friend struct QMetaObject;
379 friend struct QMetaObjectPrivate;
380 friend class QMetaCallEvent;
381 friend class QApplication;
382 friend class QApplicationPrivate;
383 friend class QCoreApplication;
384 friend class QCoreApplicationPrivate;
385 friend class QWidget;
386 friend class QAccessibleWidget;
387 friend class QThreadData;
390 void doSetObjectName(
const QString &name);
391#if QT_CORE_REMOVED_SINCE(6
, 10
)
392 bool doSetProperty(
const char *name,
const QVariant *lvalue, QVariant *rvalue);
394 bool doSetProperty(
const char *name,
const QVariant &value, QVariant *rvalue);
396 Q_DISABLE_COPY(QObject)
399 static QMetaObject::Connection connectImpl(
const QObject *sender,
void **signal,
400 const QObject *receiver,
void **slotPtr,
401 QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type,
402 const int *types,
const QMetaObject *senderMetaObject);
404 static bool disconnectImpl(
const QObject *sender,
void **signal,
const QObject *receiver,
void **slot,
405 const QMetaObject *senderMetaObject);