109 Q_PROPERTY(QString objectName READ objectName WRITE setObjectName NOTIFY objectNameChanged
110 BINDABLE bindableObjectName)
111 Q_DECLARE_PRIVATE(QObject)
114 Q_INVOKABLE
explicit QObject(QObject *parent =
nullptr);
117 virtual bool event(QEvent *event);
118 virtual bool eventFilter(QObject *watched, QEvent *event);
120#if defined(QT_NO_TRANSLATION) || defined(Q_QDOC)
121 static QString tr(
const char *sourceText,
const char * =
nullptr,
int = -1)
122 {
return QString::fromUtf8(sourceText); }
125 QString objectName()
const;
126#if QT_CORE_REMOVED_SINCE(6
, 4
)
127 void setObjectName(
const QString &name);
130 void setObjectName(
const QString &name) { doSetObjectName(name); }
131 void setObjectName(QAnyStringView name);
132 QBindable<QString> bindableObjectName();
134 inline bool isWidgetType()
const {
return d_ptr->isWidget; }
135 inline bool isWindowType()
const {
return d_ptr->isWindow; }
136 inline bool isQuickItemType()
const {
return d_ptr->isQuickItem; }
138 bool isQmlExposed()
const noexcept;
140 inline bool signalsBlocked()
const noexcept {
return d_ptr->blockSig; }
141 bool blockSignals(
bool b)
noexcept;
143 QThread *thread()
const;
144#if QT_CORE_REMOVED_SINCE(6
, 7
)
145 void moveToThread(QThread *thread);
147 bool moveToThread(QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL);
149 int startTimer(
int interval, Qt::TimerType timerType = Qt::CoarseTimer);
151#if QT_CORE_REMOVED_SINCE(6
, 8
)
152 int startTimer(std::chrono::milliseconds time, Qt::TimerType timerType = Qt::CoarseTimer);
154 int startTimer(std::chrono::nanoseconds time, Qt::TimerType timerType = Qt::CoarseTimer);
156 void killTimer(
int id);
157 void killTimer(Qt::TimerId id);
160 T findChild(QAnyStringView aName, Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
162 typedef typename std::remove_cv<
typename std::remove_pointer<T>::type>::type ObjType;
163 static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
164 "No Q_OBJECT in the class passed to QObject::findChild");
165 return static_cast<T>(qt_qFindChild_helper(
this, aName, ObjType::staticMetaObject, options));
169 QList<T> findChildren(QAnyStringView aName, Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
171 typedef typename std::remove_cv<
typename std::remove_pointer<T>::type>::type ObjType;
172 static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
173 "No Q_OBJECT in the class passed to QObject::findChildren");
175 qt_qFindChildren_helper(
this, aName, ObjType::staticMetaObject,
176 reinterpret_cast<QList<
void *> *>(&list), options);
181 T findChild(Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
183 return findChild<T>({}, options);
187 QList<T> findChildren(Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
189 return findChildren<T>(QAnyStringView{}, options);
192#if QT_CONFIG(regularexpression)
194 inline QList<T> findChildren(
const QRegularExpression &re, Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
196 typedef typename std::remove_cv<
typename std::remove_pointer<T>::type>::type ObjType;
197 static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
198 "No Q_OBJECT in the class passed to QObject::findChildren");
200 qt_qFindChildren_helper(
this, re, ObjType::staticMetaObject,
201 reinterpret_cast<QList<
void *> *>(&list), options);
206 inline const QObjectList &children()
const {
return d_ptr->children; }
208 void setParent(QObject *parent);
209 void installEventFilter(QObject *filterObj);
210 void removeEventFilter(QObject *obj);
212 static QMetaObject::Connection connect(
const QObject *sender,
const char *signal,
213 const QObject *receiver,
const char *member, Qt::ConnectionType = Qt::AutoConnection);
215 static QMetaObject::Connection connect(
const QObject *sender,
const QMetaMethod &signal,
216 const QObject *receiver,
const QMetaMethod &method,
217 Qt::ConnectionType type = Qt::AutoConnection);
219 inline QMetaObject::Connection connect(
const QObject *sender,
const char *signal,
220 const char *member, Qt::ConnectionType type = Qt::AutoConnection)
const;
223 template<
typename PointerToMemberFunction>
224 static QMetaObject::Connection connect(
const QObject *sender, PointerToMemberFunction signal,
const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type = Qt::AutoConnection);
225 template<
typename PointerToMemberFunction,
typename Functor>
226 static QMetaObject::Connection connect(
const QObject *sender, PointerToMemberFunction signal, Functor functor);
227 template<
typename PointerToMemberFunction,
typename Functor>
228 static QMetaObject::Connection connect(
const QObject *sender, PointerToMemberFunction signal,
const QObject *context, Functor functor, Qt::ConnectionType type = Qt::AutoConnection);
231 template <
typename Func1,
typename Func2>
232 static inline QMetaObject::Connection
233 connect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
234 const typename QtPrivate::ContextTypeForFunctor<Func2>::ContextType *context, Func2 &&slot,
235 Qt::ConnectionType type = Qt::AutoConnection)
237 typedef QtPrivate::FunctionPointer<Func1> SignalType;
238 typedef QtPrivate::FunctionPointer<std::decay_t<Func2>> SlotType;
240 if constexpr (SlotType::ArgumentCount != -1) {
241 static_assert((QtPrivate::AreArgumentsCompatible<
typename SlotType::ReturnType,
typename SignalType::ReturnType>::value),
242 "Return type of the slot is not compatible with the return type of the signal.");
244 constexpr int FunctorArgumentCount = QtPrivate::ComputeFunctorArgumentCount<std::decay_t<Func2>,
typename SignalType::Arguments>::Value;
246 constexpr int SlotArgumentCount = (FunctorArgumentCount >= 0) ? FunctorArgumentCount : 0;
247 typedef typename QtPrivate::FunctorReturnType<std::decay_t<Func2>,
typename QtPrivate::List_Left<
typename SignalType::Arguments, SlotArgumentCount>::Value>::type SlotReturnType;
249 static_assert((QtPrivate::AreArgumentsCompatible<SlotReturnType,
typename SignalType::ReturnType>::value),
250 "Return type of the slot is not compatible with the return type of the signal.");
253 static_assert(QtPrivate::HasQ_OBJECT_Macro<
typename SignalType::Object>::Value,
254 "No Q_OBJECT in the class with the signal");
257 static_assert(
int(SignalType::ArgumentCount) >=
int(SlotType::ArgumentCount),
258 "The slot requires more arguments than the signal provides.");
260 const int *types =
nullptr;
261 if (type == Qt::QueuedConnection || type == Qt::BlockingQueuedConnection)
262 types = QtPrivate::ConnectionTypes<
typename SignalType::Arguments>::types();
264 void **pSlot =
nullptr;
265 if constexpr (std::is_member_function_pointer_v<std::decay_t<Func2>>) {
266 pSlot =
const_cast<
void **>(
reinterpret_cast<
void *
const *>(&slot));
268 Q_ASSERT_X((type & Qt::UniqueConnection) == 0,
"",
269 "QObject::connect: Unique connection requires the slot to be a pointer to "
270 "a member function of a QObject subclass.");
273 return connectImpl(sender,
reinterpret_cast<
void **>(&signal), context, pSlot,
274 QtPrivate::makeCallableObject<Func1>(std::forward<Func2>(slot)),
275 type, types, &SignalType::Object::staticMetaObject);
278#ifndef QT_NO_CONTEXTLESS_CONNECT
280 template <
typename Func1,
typename Func2>
281 static inline QMetaObject::Connection
282 connect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 &&slot)
284 return connect(sender, signal, sender, std::forward<Func2>(slot), Qt::DirectConnection);
289 static bool disconnect(
const QObject *sender,
const char *signal,
290 const QObject *receiver,
const char *member);
291 static bool disconnect(
const QObject *sender,
const QMetaMethod &signal,
292 const QObject *receiver,
const QMetaMethod &member);
293 inline bool disconnect(
const char *signal =
nullptr,
294 const QObject *receiver =
nullptr,
const char *member =
nullptr)
const
295 {
return disconnect(
this, signal, receiver, member); }
296 inline bool disconnect(
const QObject *receiver,
const char *member =
nullptr)
const
297 {
return disconnect(
this,
nullptr, receiver, member); }
298 static bool disconnect(
const QMetaObject::Connection &);
301 template<
typename PointerToMemberFunction>
302 static bool disconnect(
const QObject *sender, PointerToMemberFunction signal,
const QObject *receiver, PointerToMemberFunction method);
304 template <
typename Func1,
typename Func2>
305 static inline bool disconnect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
306 const typename QtPrivate::FunctionPointer<Func2>::Object *receiver, Func2 slot)
308 typedef QtPrivate::FunctionPointer<Func1> SignalType;
309 typedef QtPrivate::FunctionPointer<Func2> SlotType;
311 static_assert(QtPrivate::HasQ_OBJECT_Macro<
typename SignalType::Object>::Value,
312 "No Q_OBJECT in the class with the signal");
315 static_assert((QtPrivate::CheckCompatibleArguments<
typename SignalType::Arguments,
typename SlotType::Arguments>::value),
316 "Signal and slot arguments are not compatible.");
318 return disconnectImpl(sender,
reinterpret_cast<
void **>(&signal), receiver,
reinterpret_cast<
void **>(&slot),
319 &SignalType::Object::staticMetaObject);
321 template <
typename Func1>
322 static inline bool disconnect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
323 const QObject *receiver,
void **zero)
329 typedef QtPrivate::FunctionPointer<Func1> SignalType;
330 return disconnectImpl(sender,
reinterpret_cast<
void **>(&signal), receiver, zero,
331 &SignalType::Object::staticMetaObject);
335 void dumpObjectTree()
const;
336 void dumpObjectInfo()
const;
338 QT_CORE_INLINE_SINCE(6, 6)
339 bool setProperty(
const char *name,
const QVariant &value);
340 inline bool setProperty(
const char *name, QVariant &&value);
341 QVariant property(
const char *name)
const;
342 QList<QByteArray> dynamicPropertyNames()
const;
343 QBindingStorage *bindingStorage() {
return &d_ptr->bindingStorage; }
344 const QBindingStorage *bindingStorage()
const {
return &d_ptr->bindingStorage; }
347 void destroyed(QObject * =
nullptr);
348 void objectNameChanged(
const QString &objectName, QPrivateSignal);
351 inline QObject *parent()
const {
return d_ptr->parent; }
353 inline bool inherits(
const char *classname)
const
355 return const_cast<QObject *>(
this)->qt_metacast(classname) !=
nullptr;
362 QObject *sender()
const;
363 int senderSignalIndex()
const;
364 int receivers(
const char *signal)
const;
365 bool isSignalConnected(
const QMetaMethod &signal)
const;
367 virtual void timerEvent(QTimerEvent *event);
368 virtual void childEvent(QChildEvent *event);
369 virtual void customEvent(QEvent *event);
371 virtual void connectNotify(
const QMetaMethod &signal);
372 virtual void disconnectNotify(
const QMetaMethod &signal);
375 QObject(QObjectPrivate &dd, QObject *parent =
nullptr);
378 QScopedPointer<QObjectData> d_ptr;
380 friend struct QMetaObject;
381 friend struct QMetaObjectPrivate;
382 friend class QMetaCallEvent;
383 friend class QApplication;
384 friend class QApplicationPrivate;
385 friend class QCoreApplication;
386 friend class QCoreApplicationPrivate;
387 friend class QWidget;
388 friend class QAccessibleWidget;
389 friend class QThreadData;
392 void doSetObjectName(
const QString &name);
393#if QT_CORE_REMOVED_SINCE(6
, 10
)
394 bool doSetProperty(
const char *name,
const QVariant *lvalue, QVariant *rvalue);
396 bool doSetProperty(
const char *name,
const QVariant &value, QVariant *rvalue);
398 Q_DISABLE_COPY(QObject)
401 static QMetaObject::Connection connectImpl(
const QObject *sender,
void **signal,
402 const QObject *receiver,
void **slotPtr,
403 QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type,
404 const int *types,
const QMetaObject *senderMetaObject);
406 static bool disconnectImpl(
const QObject *sender,
void **signal,
const QObject *receiver,
void **slot,
407 const QMetaObject *senderMetaObject);