Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:27:32

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QSIGNALSPY_H
0005 #define QSIGNALSPY_H
0006 
0007 #include <QtCore/qbytearray.h>
0008 #include <QtCore/qlist.h>
0009 #include <QtCore/qmetaobject.h>
0010 #include <QtTest/qtesteventloop.h>
0011 #include <QtCore/qvariant.h>
0012 #include <QtCore/qmutex.h>
0013 
0014 #include <memory>
0015 
0016 QT_BEGIN_NAMESPACE
0017 
0018 
0019 class QVariant;
0020 class QSignalSpyPrivate;
0021 class QSignalSpy : public QList<QList<QVariant> >
0022 {
0023     struct ObjectSignal {
0024         const QObject *obj;
0025         QMetaMethod sig;
0026     };
0027     friend class QSignalSpyPrivate;
0028     std::unique_ptr<QSignalSpyPrivate> d_ptr;
0029 public:
0030     explicit QSignalSpy(const QObject *obj, const char *aSignal)
0031         : QSignalSpy(verify(obj, aSignal)) {}
0032 #ifdef Q_QDOC
0033     template <typename PointerToMemberFunction>
0034     QSignalSpy(const QObject *object, PointerToMemberFunction signal);
0035 #else
0036     template <typename Func>
0037     QSignalSpy(const typename QtPrivate::FunctionPointer<Func>::Object *obj, Func signal0)
0038         : QSignalSpy(verify(obj, QMetaMethod::fromSignal(signal0))) {}
0039 #endif // Q_QDOC
0040     QSignalSpy(const QObject *obj, QMetaMethod signal)
0041         : QSignalSpy(verify(obj, signal)) {}
0042     Q_TESTLIB_EXPORT ~QSignalSpy();
0043 
0044     bool isValid() const noexcept { return d_ptr != nullptr; }
0045     inline QByteArray signal() const { return sig; }
0046 
0047     bool wait(int timeout)
0048     { return wait(std::chrono::milliseconds{timeout}); }
0049 
0050     Q_TESTLIB_EXPORT bool wait(std::chrono::milliseconds timeout = std::chrono::seconds{5});
0051 
0052 private:
0053     Q_TESTLIB_EXPORT explicit QSignalSpy(ObjectSignal os);
0054 
0055     Q_TESTLIB_EXPORT static ObjectSignal verify(const QObject *obj, QMetaMethod signal);
0056     Q_TESTLIB_EXPORT static ObjectSignal verify(const QObject *obj, const char *aSignal);
0057 
0058     Q_TESTLIB_EXPORT void appendArgs(void **a);
0059 
0060     // the full, normalized signal name
0061     const QByteArray sig;
0062     // holds the QMetaType types for the argument list of the signal
0063     const QList<int> args;
0064 
0065     QTestEventLoop m_loop;
0066     bool m_waiting = false;
0067     QMutex m_mutex; // protects m_waiting and the QList base class, between appendArgs() and wait()
0068 };
0069 
0070 QT_END_NAMESPACE
0071 
0072 #endif