summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2021-02-26 12:04:43 +0200
committerJuha Vuolle <juha.vuolle@insta.fi>2021-03-08 18:43:20 +0200
commit9c7adbc5d20114146d17a19a1d177ca324f7dd06 (patch)
tree2dacc29333570c56b4779176de5a18e65d62e06c
parentdee2648c8066214039b77081306fd4e227366df6 (diff)
Add const to QSignalTransition::senderObject QObject*
The setSenderObject() takes in a const QObject* whereas the getter senderObject() returns non-const QObject*, and the related Q_PROPERTY is defined as non-const QObject*. This asymmetric API was introduced in 8b032fe423e854428c1c8324dcd0f8c6150b3503 (qtbase), and is a candidate for causing undefined behavior. This commit changes both the getter and the related Q_PROPERTY to also be const QObject*. Task-number: QTBUG-89832 Change-Id: I691da8e90f750b0d73f8f532da6d040bb8941eab Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit f2446f08d6ab9102e0bccd2f10a765f25ee2b97e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/statemachine/doc/qt6-changes.qdoc9
-rw-r--r--src/statemachine/qsignaltransition.cpp4
-rw-r--r--src/statemachine/qsignaltransition.h4
-rw-r--r--src/statemachineqml/signaltransition.cpp2
4 files changed, 13 insertions, 6 deletions
diff --git a/src/statemachine/doc/qt6-changes.qdoc b/src/statemachine/doc/qt6-changes.qdoc
index ad202eb..1aa4343 100644
--- a/src/statemachine/doc/qt6-changes.qdoc
+++ b/src/statemachine/doc/qt6-changes.qdoc
@@ -41,12 +41,19 @@
In this topic we summarize those changes in Qt State Machine module, and provide
guidance to handle them.
- \section1 Changes overview
+ \section1 Changes
The Qt StateMachine module is generally speaking source compatible with the Qt5
version and users of the library should be able to continue with no or
minor changes to their project.
+ \section2 QSignalTransition
+
+ The \l [CPP] QSignalTransition::senderObject() getter and the related
+ Q_PROPERTY now also use const QObject*. These are now better aligned
+ with the setter \l [CPP] QSignalTransition::setSenderObject(const QObject*) that takes a
+ const QObject* as a parameter.
+
\section1 Build system
As with Qt 6 in general, the Qt State Machine module has cmake support in addition
diff --git a/src/statemachine/qsignaltransition.cpp b/src/statemachine/qsignaltransition.cpp
index bdfa166..ff60a66 100644
--- a/src/statemachine/qsignaltransition.cpp
+++ b/src/statemachine/qsignaltransition.cpp
@@ -169,10 +169,10 @@ QSignalTransition::~QSignalTransition()
/*!
Returns the sender object associated with this signal transition.
*/
-QObject *QSignalTransition::senderObject() const
+const QObject *QSignalTransition::senderObject() const
{
Q_D(const QSignalTransition);
- return const_cast<QObject *>(d->sender);
+ return d->sender;
}
/*!
diff --git a/src/statemachine/qsignaltransition.h b/src/statemachine/qsignaltransition.h
index 7e64b4c..d431474 100644
--- a/src/statemachine/qsignaltransition.h
+++ b/src/statemachine/qsignaltransition.h
@@ -51,7 +51,7 @@ class QSignalTransitionPrivate;
class Q_STATEMACHINE_EXPORT QSignalTransition : public QAbstractTransition
{
Q_OBJECT
- Q_PROPERTY(QObject* senderObject READ senderObject WRITE setSenderObject NOTIFY senderObjectChanged)
+ Q_PROPERTY(const QObject* senderObject READ senderObject WRITE setSenderObject NOTIFY senderObjectChanged)
Q_PROPERTY(QByteArray signal READ signal WRITE setSignal NOTIFY signalChanged)
public:
@@ -73,7 +73,7 @@ public:
~QSignalTransition();
- QObject *senderObject() const;
+ const QObject *senderObject() const;
void setSenderObject(const QObject *sender);
QByteArray signal() const;
diff --git a/src/statemachineqml/signaltransition.cpp b/src/statemachineqml/signaltransition.cpp
index 5c60ed8..16c2e0c 100644
--- a/src/statemachineqml/signaltransition.cpp
+++ b/src/statemachineqml/signaltransition.cpp
@@ -159,7 +159,7 @@ void SignalTransition::connectTriggered()
if (!m_complete || !m_compilationUnit)
return;
- QObject *target = senderObject();
+ const QObject *target = senderObject();
QQmlData *ddata = QQmlData::get(this);
QQmlRefPointer<QQmlContextData> ctxtdata = ddata ? ddata->outerContext : nullptr;