106 Q_PROPERTY(QString objectName READ objectName WRITE setObjectName NOTIFY objectNameChanged
107 BINDABLE bindableObjectName)
108 Q_DECLARE_PRIVATE(QObject)
111 Q_INVOKABLE
explicit QObject(QObject *parent =
nullptr);
114 virtual bool event(QEvent *event);
115 virtual bool eventFilter(QObject *watched, QEvent *event);
117#if defined(QT_NO_TRANSLATION) || defined(Q_QDOC)
118 static QString tr(
const char *sourceText,
const char * =
nullptr,
int = -1)
119 {
return QString::fromUtf8(sourceText); }
122 QString objectName()
const;
123#if QT_CORE_REMOVED_SINCE(6
, 4
)
124 void setObjectName(
const QString &name);
127 void setObjectName(
const QString &name) { doSetObjectName(name); }
128 void setObjectName(QAnyStringView name);
129 QBindable<QString> bindableObjectName();
131 inline bool isWidgetType()
const {
return d_ptr->isWidget; }
132 inline bool isWindowType()
const {
return d_ptr->isWindow; }
133 inline bool isQuickItemType()
const {
return d_ptr->isQuickItem; }
135 inline bool signalsBlocked()
const noexcept {
return d_ptr->blockSig; }
136 bool blockSignals(
bool b)
noexcept;
138 QThread *thread()
const;
139#if QT_CORE_REMOVED_SINCE(6
, 7
)
140 void moveToThread(QThread *thread);
142 bool moveToThread(QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL);
144 int startTimer(
int interval, Qt::TimerType timerType = Qt::CoarseTimer);
146#if QT_CORE_REMOVED_SINCE(6
, 8
)
147 int startTimer(std::chrono::milliseconds time, Qt::TimerType timerType = Qt::CoarseTimer);
149 int startTimer(std::chrono::nanoseconds time, Qt::TimerType timerType = Qt::CoarseTimer);
151 void killTimer(
int id);
152 void killTimer(Qt::TimerId id);
155 T findChild(QAnyStringView aName, Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
157 typedef typename std::remove_cv<
typename std::remove_pointer<T>::type>::type ObjType;
158 static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
159 "No Q_OBJECT in the class passed to QObject::findChild");
160 return static_cast<T>(qt_qFindChild_helper(
this, aName, ObjType::staticMetaObject, options));
164 QList<T> findChildren(QAnyStringView aName, Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
166 typedef typename std::remove_cv<
typename std::remove_pointer<T>::type>::type ObjType;
167 static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
168 "No Q_OBJECT in the class passed to QObject::findChildren");
170 qt_qFindChildren_helper(
this, aName, ObjType::staticMetaObject,
171 reinterpret_cast<QList<
void *> *>(&list), options);
176 T findChild(Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
178 return findChild<T>({}, options);
182 QList<T> findChildren(Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
184 return findChildren<T>(QAnyStringView{}, options);
187#if QT_CONFIG(regularexpression)
189 inline QList<T> findChildren(
const QRegularExpression &re, Qt::FindChildOptions options = Qt::FindChildrenRecursively)
const
191 typedef typename std::remove_cv<
typename std::remove_pointer<T>::type>::type ObjType;
192 static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
193 "No Q_OBJECT in the class passed to QObject::findChildren");
195 qt_qFindChildren_helper(
this, re, ObjType::staticMetaObject,
196 reinterpret_cast<QList<
void *> *>(&list), options);
201 inline const QObjectList &children()
const {
return d_ptr->children; }
203 void setParent(QObject *parent);
204 void installEventFilter(QObject *filterObj);
205 void removeEventFilter(QObject *obj);
207 static QMetaObject::Connection connect(
const QObject *sender,
const char *signal,
208 const QObject *receiver,
const char *member, Qt::ConnectionType = Qt::AutoConnection);
210 static QMetaObject::Connection connect(
const QObject *sender,
const QMetaMethod &signal,
211 const QObject *receiver,
const QMetaMethod &method,
212 Qt::ConnectionType type = Qt::AutoConnection);
214 inline QMetaObject::Connection connect(
const QObject *sender,
const char *signal,
215 const char *member, Qt::ConnectionType type = Qt::AutoConnection)
const;
218 template<
typename PointerToMemberFunction>
219 static QMetaObject::Connection connect(
const QObject *sender, PointerToMemberFunction signal,
const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type = Qt::AutoConnection);
220 template<
typename PointerToMemberFunction,
typename Functor>
221 static QMetaObject::Connection connect(
const QObject *sender, PointerToMemberFunction signal, Functor functor);
222 template<
typename PointerToMemberFunction,
typename Functor>
223 static QMetaObject::Connection connect(
const QObject *sender, PointerToMemberFunction signal,
const QObject *context, Functor functor, Qt::ConnectionType type = Qt::AutoConnection);
226 template <
typename Func1,
typename Func2>
227 static inline QMetaObject::Connection
228 connect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
229 const typename QtPrivate::ContextTypeForFunctor<Func2>::ContextType *context, Func2 &&slot,
230 Qt::ConnectionType type = Qt::AutoConnection)
232 typedef QtPrivate::FunctionPointer<Func1> SignalType;
233 typedef QtPrivate::FunctionPointer<std::decay_t<Func2>> SlotType;
235 if constexpr (SlotType::ArgumentCount != -1) {
236 static_assert((QtPrivate::AreArgumentsCompatible<
typename SlotType::ReturnType,
typename SignalType::ReturnType>::value),
237 "Return type of the slot is not compatible with the return type of the signal.");
239 constexpr int FunctorArgumentCount = QtPrivate::ComputeFunctorArgumentCount<std::decay_t<Func2>,
typename SignalType::Arguments>::Value;
241 constexpr int SlotArgumentCount = (FunctorArgumentCount >= 0) ? FunctorArgumentCount : 0;
242 typedef typename QtPrivate::FunctorReturnType<std::decay_t<Func2>,
typename QtPrivate::List_Left<
typename SignalType::Arguments, SlotArgumentCount>::Value>::type SlotReturnType;
244 static_assert((QtPrivate::AreArgumentsCompatible<SlotReturnType,
typename SignalType::ReturnType>::value),
245 "Return type of the slot is not compatible with the return type of the signal.");
248 static_assert(QtPrivate::HasQ_OBJECT_Macro<
typename SignalType::Object>::Value,
249 "No Q_OBJECT in the class with the signal");
252 static_assert(
int(SignalType::ArgumentCount) >=
int(SlotType::ArgumentCount),
253 "The slot requires more arguments than the signal provides.");
255 const int *types =
nullptr;
256 if (type == Qt::QueuedConnection || type == Qt::BlockingQueuedConnection)
257 types = QtPrivate::ConnectionTypes<
typename SignalType::Arguments>::types();
259 void **pSlot =
nullptr;
260 if constexpr (std::is_member_function_pointer_v<std::decay_t<Func2>>) {
261 pSlot =
const_cast<
void **>(
reinterpret_cast<
void *
const *>(&slot));
263 Q_ASSERT_X((type & Qt::UniqueConnection) == 0,
"",
264 "QObject::connect: Unique connection requires the slot to be a pointer to "
265 "a member function of a QObject subclass.");
268 return connectImpl(sender,
reinterpret_cast<
void **>(&signal), context, pSlot,
269 QtPrivate::makeCallableObject<Func1>(std::forward<Func2>(slot)),
270 type, types, &SignalType::Object::staticMetaObject);
273#ifndef QT_NO_CONTEXTLESS_CONNECT
275 template <
typename Func1,
typename Func2>
276 static inline QMetaObject::Connection
277 connect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 &&slot)
279 return connect(sender, signal, sender, std::forward<Func2>(slot), Qt::DirectConnection);
284 static bool disconnect(
const QObject *sender,
const char *signal,
285 const QObject *receiver,
const char *member);
286 static bool disconnect(
const QObject *sender,
const QMetaMethod &signal,
287 const QObject *receiver,
const QMetaMethod &member);
288 inline bool disconnect(
const char *signal =
nullptr,
289 const QObject *receiver =
nullptr,
const char *member =
nullptr)
const
290 {
return disconnect(
this, signal, receiver, member); }
291 inline bool disconnect(
const QObject *receiver,
const char *member =
nullptr)
const
292 {
return disconnect(
this,
nullptr, receiver, member); }
293 static bool disconnect(
const QMetaObject::Connection &);
296 template<
typename PointerToMemberFunction>
297 static bool disconnect(
const QObject *sender, PointerToMemberFunction signal,
const QObject *receiver, PointerToMemberFunction method);
299 template <
typename Func1,
typename Func2>
300 static inline bool disconnect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
301 const typename QtPrivate::FunctionPointer<Func2>::Object *receiver, Func2 slot)
303 typedef QtPrivate::FunctionPointer<Func1> SignalType;
304 typedef QtPrivate::FunctionPointer<Func2> SlotType;
306 static_assert(QtPrivate::HasQ_OBJECT_Macro<
typename SignalType::Object>::Value,
307 "No Q_OBJECT in the class with the signal");
310 static_assert((QtPrivate::CheckCompatibleArguments<
typename SignalType::Arguments,
typename SlotType::Arguments>::value),
311 "Signal and slot arguments are not compatible.");
313 return disconnectImpl(sender,
reinterpret_cast<
void **>(&signal), receiver,
reinterpret_cast<
void **>(&slot),
314 &SignalType::Object::staticMetaObject);
316 template <
typename Func1>
317 static inline bool disconnect(
const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
318 const QObject *receiver,
void **zero)
324 typedef QtPrivate::FunctionPointer<Func1> SignalType;
325 return disconnectImpl(sender,
reinterpret_cast<
void **>(&signal), receiver, zero,
326 &SignalType::Object::staticMetaObject);
330 void dumpObjectTree()
const;
331 void dumpObjectInfo()
const;
333 QT_CORE_INLINE_SINCE(6, 6)
334 bool setProperty(
const char *name,
const QVariant &value);
335 inline bool setProperty(
const char *name, QVariant &&value);
336 QVariant property(
const char *name)
const;
337 QList<QByteArray> dynamicPropertyNames()
const;
338 QBindingStorage *bindingStorage() {
return &d_ptr->bindingStorage; }
339 const QBindingStorage *bindingStorage()
const {
return &d_ptr->bindingStorage; }
342 void destroyed(QObject * =
nullptr);
343 void objectNameChanged(
const QString &objectName, QPrivateSignal);
346 inline QObject *parent()
const {
return d_ptr->parent; }
348 inline bool inherits(
const char *classname)
const
350 return const_cast<QObject *>(
this)->qt_metacast(classname) !=
nullptr;
357 QObject *sender()
const;
358 int senderSignalIndex()
const;
359 int receivers(
const char *signal)
const;
360 bool isSignalConnected(
const QMetaMethod &signal)
const;
362 virtual void timerEvent(QTimerEvent *event);
363 virtual void childEvent(QChildEvent *event);
364 virtual void customEvent(QEvent *event);
366 virtual void connectNotify(
const QMetaMethod &signal);
367 virtual void disconnectNotify(
const QMetaMethod &signal);
370 QObject(QObjectPrivate &dd, QObject *parent =
nullptr);
373 QScopedPointer<QObjectData> d_ptr;
375 friend struct QMetaObject;
376 friend struct QMetaObjectPrivate;
377 friend class QMetaCallEvent;
378 friend class QApplication;
379 friend class QApplicationPrivate;
380 friend class QCoreApplication;
381 friend class QCoreApplicationPrivate;
382 friend class QWidget;
383 friend class QAccessibleWidget;
384 friend class QThreadData;
387 void doSetObjectName(
const QString &name);
388 bool doSetProperty(
const char *name,
const QVariant *lvalue, QVariant *rvalue);
390 Q_DISABLE_COPY(QObject)
393 static QMetaObject::Connection connectImpl(
const QObject *sender,
void **signal,
394 const QObject *receiver,
void **slotPtr,
395 QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type,
396 const int *types,
const QMetaObject *senderMetaObject);
398 static bool disconnectImpl(
const QObject *sender,
void **signal,
const QObject *receiver,
void **slot,
399 const QMetaObject *senderMetaObject);