summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2024-04-16 09:20:15 +0200
committerMarc Mutz <[email protected]>2024-05-16 17:12:14 +0200
commit672afb13ca5ffc3d95ee92fb71416c6d23f7feda (patch)
treeb176792b96d4d55c266f4fe99c4cc3e9a4e8417f
parentbd01008bca729f2e935af739e2f8287633abde2b (diff)
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 <[email protected]> Reviewed-by: David Faure <[email protected]> Reviewed-by: Edward Welbourne <[email protected]>
-rw-r--r--src/testlib/qsignalspy.cpp5
-rw-r--r--src/testlib/qsignalspy.h4
2 files changed, 4 insertions, 5 deletions
diff --git a/src/testlib/qsignalspy.cpp b/src/testlib/qsignalspy.cpp
index 9902122cb4d..116ce87c3eb 100644
--- a/src/testlib/qsignalspy.cpp
+++ b/src/testlib/qsignalspy.cpp
@@ -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();
}
/*!
diff --git a/src/testlib/qsignalspy.h b/src/testlib/qsignalspy.h
index a5c960e3835..b8df2a4deb6 100644
--- a/src/testlib/qsignalspy.h
+++ b/src/testlib/qsignalspy.h
@@ -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;