Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:31:40

0001 // Copyright (C) 2020 The Qt Company Ltd.
0002 // Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.com>
0003 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0004 // Qt-Security score:significant reason:default
0005 
0006 #ifndef QOBJECT_H
0007 #define QOBJECT_H
0008 
0009 #ifndef QT_NO_QOBJECT
0010 
0011 #include <QtCore/qobjectdefs.h>
0012 #include <QtCore/qstring.h>
0013 #include <QtCore/qbytearray.h>
0014 #include <QtCore/qlist.h>
0015 #ifdef QT_INCLUDE_COMPAT
0016 #include <QtCore/qcoreevent.h>
0017 #endif
0018 #include <QtCore/qscopedpointer.h>
0019 #include <QtCore/qmetatype.h>
0020 
0021 #include <QtCore/qobject_impl.h>
0022 #include <QtCore/qbindingstorage.h>
0023 #include <QtCore/qtcoreexports.h>
0024 
0025 #include <chrono>
0026 
0027 QT_BEGIN_NAMESPACE
0028 
0029 
0030 template <typename T> class QBindable;
0031 class QEvent;
0032 class QTimerEvent;
0033 class QChildEvent;
0034 struct QMetaObject;
0035 class QVariant;
0036 class QObjectPrivate;
0037 class QObject;
0038 class QThread;
0039 class QWidget;
0040 class QAccessibleWidget;
0041 #if QT_CONFIG(regularexpression)
0042 class QRegularExpression;
0043 #endif
0044 struct QDynamicMetaObjectData;
0045 
0046 typedef QList<QObject*> QObjectList;
0047 
0048 #if QT_CORE_REMOVED_SINCE(6, 7)
0049 Q_CORE_EXPORT void qt_qFindChildren_helper(const QObject *parent, const QString &name,
0050                                            const QMetaObject &mo, QList<void *> *list, Qt::FindChildOptions options);
0051 #endif
0052 Q_CORE_EXPORT void qt_qFindChildren_helper(const QObject *parent, QAnyStringView name,
0053                                            const QMetaObject &mo, QList<void *> *list,
0054                                            Qt::FindChildOptions options);
0055 #if QT_CORE_REMOVED_SINCE(6, 7)
0056 Q_CORE_EXPORT void qt_qFindChildren_helper(const QObject *parent, const QMetaObject &mo,
0057                                            QList<void *> *list, Qt::FindChildOptions options);
0058 #endif
0059 Q_CORE_EXPORT void qt_qFindChildren_helper(const QObject *parent, const QRegularExpression &re,
0060                                            const QMetaObject &mo, QList<void *> *list, Qt::FindChildOptions options);
0061 #if QT_CORE_REMOVED_SINCE(6, 7)
0062 Q_CORE_EXPORT QObject *qt_qFindChild_helper(const QObject *parent, const QString &name, const QMetaObject &mo, Qt::FindChildOptions options);
0063 #endif
0064 Q_CORE_EXPORT QObject *qt_qFindChild_helper(const QObject *parent, QAnyStringView name,
0065                                             const QMetaObject &mo, Qt::FindChildOptions options);
0066 
0067 class Q_CORE_EXPORT QObjectData
0068 {
0069     Q_DISABLE_COPY(QObjectData)
0070 public:
0071     QObjectData() = default;
0072     virtual ~QObjectData() = 0;
0073     QObject *q_ptr;
0074     QObject *parent;
0075     QObjectList children;
0076 
0077     uint isWidget : 1;
0078     uint blockSig : 1;
0079     uint wasDeleted : 1;
0080     uint isDeletingChildren : 1;
0081     uint sendChildEvents : 1;
0082     uint receiveChildEvents : 1;
0083     uint isWindow : 1; // for QWindow
0084     uint deleteLaterCalled : 1;
0085     uint isQuickItem : 1;
0086     uint willBeWidget : 1; // for handling widget-specific bits in QObject's ctor
0087     uint wasWidget : 1; // for properly cleaning up in QObject's dtor
0088     uint receiveParentEvents: 1;
0089     uint unused : 20;
0090     QAtomicInt postedEvents;
0091     QDynamicMetaObjectData *metaObject;
0092     QBindingStorage bindingStorage;
0093 
0094 #if QT_CORE_REMOVED_SINCE(6, 9) && defined(Q_COMPILER_MANGLES_RETURN_TYPE)
0095     QMetaObject *dynamicMetaObject() const;
0096 #else
0097     const QMetaObject *dynamicMetaObject() const;
0098 #endif
0099 
0100 #ifdef QT_DEBUG
0101     enum { CheckForParentChildLoopsWarnDepth = 4096 };
0102 #endif
0103 };
0104 
0105 class Q_CORE_EXPORT QObject
0106 {
0107     Q_OBJECT
0108 
0109     Q_PROPERTY(QString objectName READ objectName WRITE setObjectName NOTIFY objectNameChanged
0110                BINDABLE bindableObjectName)
0111     Q_DECLARE_PRIVATE(QObject)
0112 
0113 public:
0114     Q_INVOKABLE explicit QObject(QObject *parent = nullptr);
0115     virtual ~QObject();
0116 
0117     virtual bool event(QEvent *event);
0118     virtual bool eventFilter(QObject *watched, QEvent *event);
0119 
0120 #if defined(QT_NO_TRANSLATION) || defined(Q_QDOC)
0121     static QString tr(const char *sourceText, const char * = nullptr, int = -1)
0122         { return QString::fromUtf8(sourceText); }
0123 #endif // QT_NO_TRANSLATION
0124 
0125     QString objectName() const;
0126 #if QT_CORE_REMOVED_SINCE(6, 4)
0127     void setObjectName(const QString &name);
0128 #endif
0129     Q_WEAK_OVERLOAD
0130     void setObjectName(const QString &name) { doSetObjectName(name); }
0131     void setObjectName(QAnyStringView name);
0132     QBindable<QString> bindableObjectName();
0133 
0134     inline bool isWidgetType() const { return d_ptr->isWidget; }
0135     inline bool isWindowType() const { return d_ptr->isWindow; }
0136     inline bool isQuickItemType() const { return d_ptr->isQuickItem; }
0137 
0138     bool isQmlExposed() const noexcept;
0139 
0140     inline bool signalsBlocked() const noexcept { return d_ptr->blockSig; }
0141     bool blockSignals(bool b) noexcept;
0142 
0143     QThread *thread() const;
0144 #if QT_CORE_REMOVED_SINCE(6, 7)
0145     void moveToThread(QThread *thread);
0146 #endif
0147     bool moveToThread(QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL);
0148 
0149     int startTimer(int interval, Qt::TimerType timerType = Qt::CoarseTimer);
0150 
0151 #if QT_CORE_REMOVED_SINCE(6, 8)
0152     int startTimer(std::chrono::milliseconds time, Qt::TimerType timerType = Qt::CoarseTimer);
0153 #endif
0154     int startTimer(std::chrono::nanoseconds time, Qt::TimerType timerType = Qt::CoarseTimer);
0155 
0156     void killTimer(int id);
0157     void killTimer(Qt::TimerId id);
0158 
0159     template<typename T>
0160     T findChild(QAnyStringView aName, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
0161     {
0162         typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type ObjType;
0163         static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
0164                           "No Q_OBJECT in the class passed to QObject::findChild");
0165         return static_cast<T>(qt_qFindChild_helper(this, aName, ObjType::staticMetaObject, options));
0166     }
0167 
0168     template<typename T>
0169     QList<T> findChildren(QAnyStringView aName, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
0170     {
0171         typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type ObjType;
0172         static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
0173                           "No Q_OBJECT in the class passed to QObject::findChildren");
0174         QList<T> list;
0175         qt_qFindChildren_helper(this, aName, ObjType::staticMetaObject,
0176                                 reinterpret_cast<QList<void *> *>(&list), options);
0177         return list;
0178     }
0179 
0180     template<typename T>
0181     T findChild(Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
0182     {
0183         return findChild<T>({}, options);
0184     }
0185 
0186     template<typename T>
0187     QList<T> findChildren(Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
0188     {
0189         return findChildren<T>(QAnyStringView{}, options);
0190     }
0191 
0192 #if QT_CONFIG(regularexpression)
0193     template<typename T>
0194     inline QList<T> findChildren(const QRegularExpression &re, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
0195     {
0196         typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type ObjType;
0197         static_assert(QtPrivate::HasQ_OBJECT_Macro<ObjType>::Value,
0198                           "No Q_OBJECT in the class passed to QObject::findChildren");
0199         QList<T> list;
0200         qt_qFindChildren_helper(this, re, ObjType::staticMetaObject,
0201                                 reinterpret_cast<QList<void *> *>(&list), options);
0202         return list;
0203     }
0204 #endif // QT_CONFIG(regularexpression)
0205 
0206     inline const QObjectList &children() const { return d_ptr->children; }
0207 
0208     void setParent(QObject *parent);
0209     void installEventFilter(QObject *filterObj);
0210     void removeEventFilter(QObject *obj);
0211 
0212     static QMetaObject::Connection connect(const QObject *sender, const char *signal,
0213                         const QObject *receiver, const char *member, Qt::ConnectionType = Qt::AutoConnection);
0214 
0215     static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
0216                         const QObject *receiver, const QMetaMethod &method,
0217                         Qt::ConnectionType type = Qt::AutoConnection);
0218 
0219     inline QMetaObject::Connection connect(const QObject *sender, const char *signal,
0220                         const char *member, Qt::ConnectionType type = Qt::AutoConnection) const;
0221 
0222 #ifdef Q_QDOC
0223     template<typename PointerToMemberFunction>
0224     static QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type = Qt::AutoConnection);
0225     template<typename PointerToMemberFunction, typename Functor>
0226     static QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor);
0227     template<typename PointerToMemberFunction, typename Functor>
0228     static QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type = Qt::AutoConnection);
0229 #else
0230     //connect with context
0231     template <typename Func1, typename Func2>
0232     static inline QMetaObject::Connection
0233         connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
0234                 const typename QtPrivate::ContextTypeForFunctor<Func2>::ContextType *context, Func2 &&slot,
0235                 Qt::ConnectionType type = Qt::AutoConnection)
0236     {
0237         typedef QtPrivate::FunctionPointer<Func1> SignalType;
0238         typedef QtPrivate::FunctionPointer<std::decay_t<Func2>> SlotType;
0239 
0240         if constexpr (SlotType::ArgumentCount != -1) {
0241             static_assert((QtPrivate::AreArgumentsCompatible<typename SlotType::ReturnType, typename SignalType::ReturnType>::value),
0242                             "Return type of the slot is not compatible with the return type of the signal.");
0243         } else {
0244             constexpr int FunctorArgumentCount = QtPrivate::ComputeFunctorArgumentCount<std::decay_t<Func2>, typename SignalType::Arguments>::Value;
0245             [[maybe_unused]]
0246             constexpr int SlotArgumentCount = (FunctorArgumentCount >= 0) ? FunctorArgumentCount : 0;
0247             typedef typename QtPrivate::FunctorReturnType<std::decay_t<Func2>, typename QtPrivate::List_Left<typename SignalType::Arguments, SlotArgumentCount>::Value>::type SlotReturnType;
0248 
0249             static_assert((QtPrivate::AreArgumentsCompatible<SlotReturnType, typename SignalType::ReturnType>::value),
0250                             "Return type of the slot is not compatible with the return type of the signal.");
0251         }
0252 
0253         static_assert(QtPrivate::HasQ_OBJECT_Macro<typename SignalType::Object>::Value,
0254                           "No Q_OBJECT in the class with the signal");
0255 
0256         //compilation error if the arguments does not match.
0257         static_assert(int(SignalType::ArgumentCount) >= int(SlotType::ArgumentCount),
0258                           "The slot requires more arguments than the signal provides.");
0259 
0260         const int *types = nullptr;
0261         if (type == Qt::QueuedConnection || type == Qt::BlockingQueuedConnection)
0262             types = QtPrivate::ConnectionTypes<typename SignalType::Arguments>::types();
0263 
0264         void **pSlot = nullptr;
0265         if constexpr (std::is_member_function_pointer_v<std::decay_t<Func2>>) {
0266             pSlot = const_cast<void **>(reinterpret_cast<void *const *>(&slot));
0267         } else {
0268             Q_ASSERT_X((type & Qt::UniqueConnection) == 0, "",
0269                        "QObject::connect: Unique connection requires the slot to be a pointer to "
0270                        "a member function of a QObject subclass.");
0271         }
0272 
0273         return connectImpl(sender, reinterpret_cast<void **>(&signal), context, pSlot,
0274                            QtPrivate::makeCallableObject<Func1>(std::forward<Func2>(slot)),
0275                            type, types, &SignalType::Object::staticMetaObject);
0276     }
0277 
0278 #ifndef QT_NO_CONTEXTLESS_CONNECT
0279     //connect without context
0280     template <typename Func1, typename Func2>
0281     static inline QMetaObject::Connection
0282         connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 &&slot)
0283     {
0284         return connect(sender, signal, sender, std::forward<Func2>(slot), Qt::DirectConnection);
0285     }
0286 #endif // QT_NO_CONTEXTLESS_CONNECT
0287 #endif //Q_QDOC
0288 
0289     static bool disconnect(const QObject *sender, const char *signal,
0290                            const QObject *receiver, const char *member);
0291     static bool disconnect(const QObject *sender, const QMetaMethod &signal,
0292                            const QObject *receiver, const QMetaMethod &member);
0293     inline bool disconnect(const char *signal = nullptr,
0294                            const QObject *receiver = nullptr, const char *member = nullptr) const
0295         { return disconnect(this, signal, receiver, member); }
0296     inline bool disconnect(const QObject *receiver, const char *member = nullptr) const
0297         { return disconnect(this, nullptr, receiver, member); }
0298     static bool disconnect(const QMetaObject::Connection &);
0299 
0300 #ifdef Q_QDOC
0301     template<typename PointerToMemberFunction>
0302     static bool disconnect(const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method);
0303 #else
0304     template <typename Func1, typename Func2>
0305     static inline bool disconnect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
0306                                   const typename QtPrivate::FunctionPointer<Func2>::Object *receiver, Func2 slot)
0307     {
0308         typedef QtPrivate::FunctionPointer<Func1> SignalType;
0309         typedef QtPrivate::FunctionPointer<Func2> SlotType;
0310 
0311         static_assert(QtPrivate::HasQ_OBJECT_Macro<typename SignalType::Object>::Value,
0312                           "No Q_OBJECT in the class with the signal");
0313 
0314         //compilation error if the arguments does not match.
0315         static_assert((QtPrivate::CheckCompatibleArguments<typename SignalType::Arguments, typename SlotType::Arguments>::value),
0316                           "Signal and slot arguments are not compatible.");
0317 
0318         return disconnectImpl(sender, reinterpret_cast<void **>(&signal), receiver, reinterpret_cast<void **>(&slot),
0319                               &SignalType::Object::staticMetaObject);
0320     }
0321     template <typename Func1>
0322     static inline bool disconnect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
0323                                   const QObject *receiver, void **zero)
0324     {
0325         // This is the overload for when one wish to disconnect a signal from any slot. (slot=nullptr)
0326         // Since the function template parameter cannot be deduced from '0', we use a
0327         // dummy void ** parameter that must be equal to 0
0328         Q_ASSERT(!zero);
0329         typedef QtPrivate::FunctionPointer<Func1> SignalType;
0330         return disconnectImpl(sender, reinterpret_cast<void **>(&signal), receiver, zero,
0331                               &SignalType::Object::staticMetaObject);
0332     }
0333 #endif //Q_QDOC
0334 
0335     void dumpObjectTree() const;
0336     void dumpObjectInfo() const;
0337 
0338     QT_CORE_INLINE_SINCE(6, 6)
0339     bool setProperty(const char *name, const QVariant &value);
0340     inline bool setProperty(const char *name, QVariant &&value);
0341     QVariant property(const char *name) const;
0342     QList<QByteArray> dynamicPropertyNames() const;
0343     QBindingStorage *bindingStorage() { return &d_ptr->bindingStorage; }
0344     const QBindingStorage *bindingStorage() const { return &d_ptr->bindingStorage; }
0345 
0346 Q_SIGNALS:
0347     void destroyed(QObject * = nullptr);
0348     void objectNameChanged(const QString &objectName, QPrivateSignal);
0349 
0350 public:
0351     inline QObject *parent() const { return d_ptr->parent; }
0352 
0353     inline bool inherits(const char *classname) const
0354     {
0355         return const_cast<QObject *>(this)->qt_metacast(classname) != nullptr;
0356     }
0357 
0358 public Q_SLOTS:
0359     void deleteLater();
0360 
0361 protected:
0362     QObject *sender() const;
0363     int senderSignalIndex() const;
0364     int receivers(const char *signal) const;
0365     bool isSignalConnected(const QMetaMethod &signal) const;
0366 
0367     virtual void timerEvent(QTimerEvent *event);
0368     virtual void childEvent(QChildEvent *event);
0369     virtual void customEvent(QEvent *event);
0370 
0371     virtual void connectNotify(const QMetaMethod &signal);
0372     virtual void disconnectNotify(const QMetaMethod &signal);
0373 
0374 protected:
0375     QObject(QObjectPrivate &dd, QObject *parent = nullptr);
0376 
0377 protected:
0378     QScopedPointer<QObjectData> d_ptr;
0379 
0380     friend struct QMetaObject;
0381     friend struct QMetaObjectPrivate;
0382     friend class QMetaCallEvent;
0383     friend class QApplication;
0384     friend class QApplicationPrivate;
0385     friend class QCoreApplication;
0386     friend class QCoreApplicationPrivate;
0387     friend class QWidget;
0388     friend class QAccessibleWidget;
0389     friend class QThreadData;
0390 
0391 private:
0392     void doSetObjectName(const QString &name);
0393 #if QT_CORE_REMOVED_SINCE(6, 10)
0394     bool doSetProperty(const char *name, const QVariant *lvalue, QVariant *rvalue);
0395 #endif
0396     bool doSetProperty(const char *name, const QVariant &value, QVariant *rvalue);
0397 
0398     Q_DISABLE_COPY(QObject)
0399 
0400 private:
0401     static QMetaObject::Connection connectImpl(const QObject *sender, void **signal,
0402                                                const QObject *receiver, void **slotPtr,
0403                                                QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type,
0404                                                const int *types, const QMetaObject *senderMetaObject);
0405 
0406     static bool disconnectImpl(const QObject *sender, void **signal, const QObject *receiver, void **slot,
0407                                const QMetaObject *senderMetaObject);
0408 
0409 };
0410 
0411 inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
0412                                             const char *amember, Qt::ConnectionType atype) const
0413 { return connect(asender, asignal, this, amember, atype); }
0414 
0415 #if QT_CORE_INLINE_IMPL_SINCE(6, 6)
0416 bool QObject::setProperty(const char *name, const QVariant &value)
0417 {
0418     return doSetProperty(name, value, nullptr);
0419 }
0420 #endif // inline since 6.6
0421 bool QObject::setProperty(const char *name, QVariant &&value)
0422 {
0423     return doSetProperty(name, value, &value);
0424 }
0425 
0426 template <class T>
0427 inline T qobject_cast(QObject *object)
0428 {
0429     return QtPrivate::qobject_cast_helper<T>(object);
0430 }
0431 
0432 template <class T>
0433 inline T qobject_cast(const QObject *object)
0434 {
0435     static_assert(std::is_const_v<std::remove_pointer_t<T>>,
0436                   "qobject_cast cannot cast away constness (use const_cast)");
0437     return QtPrivate::qobject_cast_helper<T>(object);
0438 }
0439 
0440 template <class T> constexpr const char * qobject_interface_iid() = delete;
0441 template <class T> inline T *
0442 qobject_iid_cast(QObject *object, const char *IId = qobject_interface_iid<T *>())
0443 {
0444     return reinterpret_cast<T *>((object ? object->qt_metacast(IId) : nullptr));
0445 }
0446 template <class T> inline std::enable_if_t<std::is_const<T>::value, T *>
0447 qobject_iid_cast(const QObject *object)
0448 {
0449     // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
0450     QObject *o = const_cast<QObject *>(object);
0451     return qobject_iid_cast<std::remove_cv_t<T>>(o);
0452 }
0453 
0454 #if defined(Q_QDOC)
0455 #  define Q_DECLARE_INTERFACE(IFace, IId)
0456 #elif !defined(Q_MOC_RUN)
0457 #  define Q_DECLARE_INTERFACE(IFace, IId) \
0458     template <> constexpr const char *qobject_interface_iid<IFace *>() \
0459     { return IId; } \
0460     template <> inline IFace *qobject_cast<IFace *>(QObject *object) \
0461     { return qobject_iid_cast<IFace>(object); } \
0462     template <> inline const IFace *qobject_cast<const IFace *>(const QObject *object) \
0463     { return qobject_iid_cast<const IFace>(object); }
0464 #endif // Q_MOC_RUN
0465 
0466 inline const QBindingStorage *qGetBindingStorage(const QObject *o)
0467 {
0468     return o->bindingStorage();
0469 }
0470 inline QBindingStorage *qGetBindingStorage(QObject *o)
0471 {
0472     return o->bindingStorage();
0473 }
0474 
0475 #ifndef QT_NO_DEBUG_STREAM
0476 Q_CORE_EXPORT QDebug operator<<(QDebug, const QObject *);
0477 #endif
0478 
0479 class QSignalBlocker
0480 {
0481 public:
0482     Q_NODISCARD_CTOR
0483     inline explicit QSignalBlocker(QObject *o) noexcept;
0484     Q_NODISCARD_CTOR
0485     inline explicit QSignalBlocker(QObject &o) noexcept;
0486     inline ~QSignalBlocker();
0487 
0488     Q_NODISCARD_CTOR
0489     inline QSignalBlocker(QSignalBlocker &&other) noexcept;
0490     inline QSignalBlocker &operator=(QSignalBlocker &&other) noexcept;
0491 
0492     inline void reblock() noexcept;
0493     inline void unblock() noexcept;
0494     inline void dismiss() noexcept;
0495 
0496 private:
0497     Q_DISABLE_COPY(QSignalBlocker)
0498     QObject *m_o;
0499     bool m_blocked;
0500     bool m_inhibited;
0501 };
0502 
0503 QSignalBlocker::QSignalBlocker(QObject *o) noexcept
0504     : m_o(o),
0505       m_blocked(o && o->blockSignals(true)),
0506       m_inhibited(false)
0507 {}
0508 
0509 QSignalBlocker::QSignalBlocker(QObject &o) noexcept
0510     : m_o(&o),
0511       m_blocked(o.blockSignals(true)),
0512       m_inhibited(false)
0513 {}
0514 
0515 QSignalBlocker::QSignalBlocker(QSignalBlocker &&other) noexcept
0516     : m_o(other.m_o),
0517       m_blocked(other.m_blocked),
0518       m_inhibited(other.m_inhibited)
0519 {
0520     other.m_o = nullptr;
0521 }
0522 
0523 QSignalBlocker &QSignalBlocker::operator=(QSignalBlocker &&other) noexcept
0524 {
0525     if (this != &other) {
0526         // if both *this and other block the same object's signals:
0527         // unblock *this iff our dtor would unblock, but other's wouldn't
0528         if (m_o != other.m_o || (!m_inhibited && other.m_inhibited))
0529             unblock();
0530         m_o = other.m_o;
0531         m_blocked = other.m_blocked;
0532         m_inhibited = other.m_inhibited;
0533         // disable other:
0534         other.m_o = nullptr;
0535     }
0536     return *this;
0537 }
0538 
0539 QSignalBlocker::~QSignalBlocker()
0540 {
0541     if (m_o && !m_inhibited)
0542         m_o->blockSignals(m_blocked);
0543 }
0544 
0545 void QSignalBlocker::reblock() noexcept
0546 {
0547     if (m_o)
0548         m_o->blockSignals(true);
0549     m_inhibited = false;
0550 }
0551 
0552 void QSignalBlocker::unblock() noexcept
0553 {
0554     if (m_o)
0555         m_o->blockSignals(m_blocked);
0556     m_inhibited = true;
0557 }
0558 
0559 void QSignalBlocker::dismiss() noexcept
0560 {
0561     m_o = nullptr;
0562 }
0563 
0564 namespace QtPrivate {
0565     inline QObject & deref_for_methodcall(QObject &o) { return  o; }
0566     inline QObject & deref_for_methodcall(QObject *o) { return *o; }
0567 }
0568 #define Q_SET_OBJECT_NAME(obj) QT_PREPEND_NAMESPACE(QtPrivate)::deref_for_methodcall(obj).setObjectName(QLatin1StringView(#obj))
0569 
0570 QT_END_NAMESPACE
0571 
0572 #endif
0573 
0574 #endif // QOBJECT_H