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; }
137 inline bool signalsBlocked()
const noexcept {
return d_ptr->blockSig; }
138 bool blockSignals(
bool b)
noexcept;
140 QThread *thread()
const;
141#if QT_CORE_REMOVED_SINCE(6
, 7
)
142 void moveToThread(QThread *thread);
144 bool moveToThread(QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL);
146 int startTimer(
int interval, Qt::TimerType timerType = Qt::CoarseTimer);
148#if QT_CORE_REMOVED_SINCE(6
, 8
)
149 int startTimer(std::chrono::milliseconds time, Qt::TimerType timerType = Qt::CoarseTimer);
151 int startTimer(std::chrono::nanoseconds time, Qt::TimerType timerType = Qt::CoarseTimer);
153 void killTimer(
int id);
154 void killTimer(Qt::TimerId id);
157 T findChild(QAnyStringView aName, Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
159 typedef typename std::remove_cv<
typename std::remove_pointer<T>::type>::type ObjType;
160 static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
161 "No Q_OBJECT in the class passed to QObject::findChild");
162 return static_cast<T>(qt_qFindChild_helper(
this, aName, ObjType::staticMetaObject, options));
166 QList<T> findChildren(QAnyStringView aName, Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
168 typedef typename std::remove_cv<
typename std::remove_pointer<T>::type>::type ObjType;
169 static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
170 "No Q_OBJECT in the class passed to QObject::findChildren");
172 qt_qFindChildren_helper(
this, aName, ObjType::staticMetaObject,
173 reinterpret_cast<QList<
void *> *>(&list), options);
178 T findChild(Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
180 return findChild<T>({}, options);
184 QList<T> findChildren(Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
186 return findChildren<T>(QAnyStringView{}, options);
189#if QT_CONFIG(regularexpression)
191 inline QList<T> findChildren(
const QRegularExpression &re, Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
193 typedef typename std::remove_cv<
typename std::remove_pointer<T>::type>::type ObjType;
194 static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
195 "No Q_OBJECT in the class passed to QObject::findChildren");
197 qt_qFindChildren_helper(
this, re, ObjType::staticMetaObject,
198 reinterpret_cast<QList<
void *> *>(&list), options);
203 inline const QObjectList &children()
const {
return d_ptr->children; }
205 void setParent(QObject *parent);
206 void installEventFilter(QObject *filterObj);
207 void removeEventFilter(QObject *obj);
209 static QMetaObject::Connection connect(
const QObject *sender,
const char *signal,
210 const QObject *receiver,
const char *member, Qt::ConnectionType = Qt::AutoConnection);
212 static QMetaObject::Connection connect(
const QObject *sender,
const QMetaMethod &signal,
213 const QObject *receiver,
const QMetaMethod &method,
214 Qt::ConnectionType type = Qt::AutoConnection);
216 inline QMetaObject::Connection connect(
const QObject *sender,
const char *signal,
217 const char *member, Qt::ConnectionType type = Qt::AutoConnection)
const;
220 template<
typename PointerToMemberFunction>
221 static QMetaObject::Connection connect(
const QObject *sender, PointerToMemberFunction signal,
const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type = Qt::AutoConnection);
222 template<
typename PointerToMemberFunction,
typename Functor>
223 static QMetaObject::Connection connect(
const QObject *sender, PointerToMemberFunction signal, Functor functor);
224 template<
typename PointerToMemberFunction,
typename Functor>
225 static QMetaObject::Connection connect(
const QObject *sender, PointerToMemberFunction signal,
const QObject *context, Functor functor, Qt::ConnectionType type = Qt::AutoConnection);
228 template <
typename Func1,
typename Func2>
229 static inline QMetaObject::Connection
230 connect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
231 const typename QtPrivate::ContextTypeForFunctor<Func2>::ContextType *context, Func2 &&slot,
232 Qt::ConnectionType type = Qt::AutoConnection)
234 typedef QtPrivate::FunctionPointer<Func1> SignalType;
235 typedef QtPrivate::FunctionPointer<std::decay_t<Func2>> SlotType;
237 if constexpr (SlotType::ArgumentCount != -1) {
238 static_assert((QtPrivate::AreArgumentsCompatible<
typename SlotType::ReturnType,
typename SignalType::ReturnType>::value),
239 "Return type of the slot is not compatible with the return type of the signal.");
241 constexpr int FunctorArgumentCount = QtPrivate::ComputeFunctorArgumentCount<std::decay_t<Func2>,
typename SignalType::Arguments>::Value;
243 constexpr int SlotArgumentCount = (FunctorArgumentCount >= 0) ? FunctorArgumentCount : 0;
244 typedef typename QtPrivate::FunctorReturnType<std::decay_t<Func2>,
typename QtPrivate::List_Left<
typename SignalType::Arguments, SlotArgumentCount>::Value>::type SlotReturnType;
246 static_assert((QtPrivate::AreArgumentsCompatible<SlotReturnType,
typename SignalType::ReturnType>::value),
247 "Return type of the slot is not compatible with the return type of the signal.");
250 static_assert(QtPrivate::HasQ_OBJECT_Macro<
typename SignalType::Object>::Value,
251 "No Q_OBJECT in the class with the signal");
254 static_assert(
int(SignalType::ArgumentCount) >=
int(SlotType::ArgumentCount),
255 "The slot requires more arguments than the signal provides.");
257 const int *types =
nullptr;
258 if (type == Qt::QueuedConnection || type == Qt::BlockingQueuedConnection)
259 types = QtPrivate::ConnectionTypes<
typename SignalType::Arguments>::types();
261 void **pSlot =
nullptr;
262 if constexpr (std::is_member_function_pointer_v<std::decay_t<Func2>>) {
263 pSlot =
const_cast<
void **>(
reinterpret_cast<
void *
const *>(&slot));
265 Q_ASSERT_X((type & Qt::UniqueConnection) == 0,
"",
266 "QObject::connect: Unique connection requires the slot to be a pointer to "
267 "a member function of a QObject subclass.");
270 return connectImpl(sender,
reinterpret_cast<
void **>(&signal), context, pSlot,
271 QtPrivate::makeCallableObject<Func1>(std::forward<Func2>(slot)),
272 type, types, &SignalType::Object::staticMetaObject);
275#ifndef QT_NO_CONTEXTLESS_CONNECT
277 template <
typename Func1,
typename Func2>
278 static inline QMetaObject::Connection
279 connect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 &&slot)
281 return connect(sender, signal, sender, std::forward<Func2>(slot), Qt::DirectConnection);
286 static bool disconnect(
const QObject *sender,
const char *signal,
287 const QObject *receiver,
const char *member);
288 static bool disconnect(
const QObject *sender,
const QMetaMethod &signal,
289 const QObject *receiver,
const QMetaMethod &member);
290 inline bool disconnect(
const char *signal =
nullptr,
291 const QObject *receiver =
nullptr,
const char *member =
nullptr)
const
292 {
return disconnect(
this, signal, receiver, member); }
293 inline bool disconnect(
const QObject *receiver,
const char *member =
nullptr)
const
294 {
return disconnect(
this,
nullptr, receiver, member); }
295 static bool disconnect(
const QMetaObject::Connection &);
298 template<
typename PointerToMemberFunction>
299 static bool disconnect(
const QObject *sender, PointerToMemberFunction signal,
const QObject *receiver, PointerToMemberFunction method);
301 template <
typename Func1,
typename Func2>
302 static inline bool disconnect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
303 const typename QtPrivate::FunctionPointer<Func2>::Object *receiver, Func2 slot)
305 typedef QtPrivate::FunctionPointer<Func1> SignalType;
306 typedef QtPrivate::FunctionPointer<Func2> SlotType;
308 static_assert(QtPrivate::HasQ_OBJECT_Macro<
typename SignalType::Object>::Value,
309 "No Q_OBJECT in the class with the signal");
312 static_assert((QtPrivate::CheckCompatibleArguments<
typename SignalType::Arguments,
typename SlotType::Arguments>::value),
313 "Signal and slot arguments are not compatible.");
315 return disconnectImpl(sender,
reinterpret_cast<
void **>(&signal), receiver,
reinterpret_cast<
void **>(&slot),
316 &SignalType::Object::staticMetaObject);
318 template <
typename Func1>
319 static inline bool disconnect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
320 const QObject *receiver,
void **zero)
326 typedef QtPrivate::FunctionPointer<Func1> SignalType;
327 return disconnectImpl(sender,
reinterpret_cast<
void **>(&signal), receiver, zero,
328 &SignalType::Object::staticMetaObject);
332 void dumpObjectTree()
const;
333 void dumpObjectInfo()
const;
335 QT_CORE_INLINE_SINCE(6, 6)
336 bool setProperty(
const char *name,
const QVariant &value);
337 inline bool setProperty(
const char *name, QVariant &&value);
338 QVariant property(
const char *name)
const;
339 QList<QByteArray> dynamicPropertyNames()
const;
340 QBindingStorage *bindingStorage() {
return &d_ptr->bindingStorage; }
341 const QBindingStorage *bindingStorage()
const {
return &d_ptr->bindingStorage; }
344 void destroyed(QObject * =
nullptr);
345 void objectNameChanged(
const QString &objectName, QPrivateSignal);
348 inline QObject *parent()
const {
return d_ptr->parent; }
350 inline bool inherits(
const char *classname)
const
352 return const_cast<QObject *>(
this)->qt_metacast(classname) !=
nullptr;
359 QObject *sender()
const;
360 int senderSignalIndex()
const;
361 int receivers(
const char *signal)
const;
362 bool isSignalConnected(
const QMetaMethod &signal)
const;
364 virtual void timerEvent(QTimerEvent *event);
365 virtual void childEvent(QChildEvent *event);
366 virtual void customEvent(QEvent *event);
368 virtual void connectNotify(
const QMetaMethod &signal);
369 virtual void disconnectNotify(
const QMetaMethod &signal);
372 QObject(QObjectPrivate &dd, QObject *parent =
nullptr);
375 QScopedPointer<QObjectData> d_ptr;
377 friend struct QMetaObject;
378 friend struct QMetaObjectPrivate;
379 friend class QMetaCallEvent;
380 friend class QApplication;
381 friend class QApplicationPrivate;
382 friend class QCoreApplication;
383 friend class QCoreApplicationPrivate;
384 friend class QWidget;
385 friend class QAccessibleWidget;
386 friend class QThreadData;
389 void doSetObjectName(
const QString &name);
390 bool doSetProperty(
const char *name,
const QVariant *lvalue, QVariant *rvalue);
392 Q_DISABLE_COPY(QObject)
395 static QMetaObject::Connection connectImpl(
const QObject *sender,
void **signal,
396 const QObject *receiver,
void **slotPtr,
397 QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type,
398 const int *types,
const QMetaObject *senderMetaObject);
400 static bool disconnectImpl(
const QObject *sender,
void **signal,
const QObject *receiver,
void **slot,
401 const QMetaObject *senderMetaObject);