QSignalSpy: make sig member const
Previously, the sig member was used to indicate successful construction of the QSignalSpy (incl. successful connection to the monitored signal), so it was set only after all other initialization had taken place, preventing it from being marked as const, which would indicate that accesses to it need not be protected by the mutex. Now that we have it, we can instead use the d_ptr's value to indicate success, and mark sig const. [ChangeLog][QtTest][Important Behavior Changes][QSignalSpy] The signal() method no longer necessarily returns an empty byte array when the connection failed. Use the existing isValid() method to determine whether a given QSignalSpy object listens to a valid signal on a valid object. Change-Id: Ia08fe3b383681f3f203cf1a121c0e1ce08ad268b Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
bd01008bca
commit
672afb13ca
@ -250,7 +250,8 @@ public:
|
||||
};
|
||||
|
||||
QSignalSpy::QSignalSpy(ObjectSignal os)
|
||||
: args(os.obj ? makeArgs(os.sig, os.obj) : QList<int>{})
|
||||
: sig(os.sig.methodSignature()),
|
||||
args(os.obj ? makeArgs(os.sig, os.obj) : QList<int>{})
|
||||
{
|
||||
if (!os.obj)
|
||||
return;
|
||||
@ -266,8 +267,6 @@ QSignalSpy::QSignalSpy(ObjectSignal os)
|
||||
}
|
||||
|
||||
d_ptr = std::move(i);
|
||||
|
||||
sig = os.sig.methodSignature();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
: QSignalSpy(verify(obj, signal)) {}
|
||||
Q_TESTLIB_EXPORT ~QSignalSpy();
|
||||
|
||||
inline bool isValid() const { return !sig.isEmpty(); }
|
||||
bool isValid() const noexcept { return d_ptr != nullptr; }
|
||||
inline QByteArray signal() const { return sig; }
|
||||
|
||||
bool wait(int timeout)
|
||||
@ -58,7 +58,7 @@ private:
|
||||
Q_TESTLIB_EXPORT void appendArgs(void **a);
|
||||
|
||||
// the full, normalized signal name
|
||||
QByteArray sig;
|
||||
const QByteArray sig;
|
||||
// holds the QMetaType types for the argument list of the signal
|
||||
const QList<int> args;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user