diff options
| author | Liu Zheng <liuzheng@uniontech.com> | 2026-06-22 15:35:39 +0800 |
|---|---|---|
| committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2026-06-25 10:50:07 +0000 |
| commit | 4d9430408fb8dddfb88b4be62de0a4f9acbf98a3 (patch) | |
| tree | 15a0c0689432e357354093cab4fe7a2a3902db35 | |
| parent | 86e0fc7f2d207671dc77f4b7583a2c5ab3196b19 (diff) | |
SpinBox: expose increase() and decrease() to QML6.11
When QQuickAbstractSpinBox was extracted as a CRTP template base
(680c871fbf3927f45fd3ad23e3ec3fa4d7e888ba), the increase() and
decrease() methods lost their Q_SLOTS declaration. As a result, these
methods are no longer registered in the meta-object system and cannot be
called from QML.
Re-declare increase() and decrease() with Q_SLOTS in both QQuickSpinBox
and QQuickDoubleSpinBox so that the moc generates the necessary
meta-method entries. It has to be done in those classes, since
QQuickAbstractSpinBox isn't a Q_OBJECT or Q_GADGET.
Fixes: QTBUG-146908
Change-Id: I032607a7dbe24114464cd5233851f6332bee801e
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
(cherry picked from commit bdba9f2707574a48c250c5e990860b444c901b1e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit cfc917802c7b95a3d9c6e17654956b532a6a2c4a)
| -rw-r--r-- | src/quicktemplates/qquickabstractspinbox_p.h | 4 | ||||
| -rw-r--r-- | src/quicktemplates/qquickdoublespinbox.cpp | 10 | ||||
| -rw-r--r-- | src/quicktemplates/qquickdoublespinbox_p.h | 4 | ||||
| -rw-r--r-- | src/quicktemplates/qquickspinbox.cpp | 10 | ||||
| -rw-r--r-- | src/quicktemplates/qquickspinbox_p.h | 4 | ||||
| -rw-r--r-- | tests/auto/quickcontrols/controls/data/tst_doublespinbox.qml | 10 | ||||
| -rw-r--r-- | tests/auto/quickcontrols/controls/data/tst_spinbox.qml | 10 |
7 files changed, 50 insertions, 2 deletions
diff --git a/src/quicktemplates/qquickabstractspinbox_p.h b/src/quicktemplates/qquickabstractspinbox_p.h index d5cdddf749..45dadc893e 100644 --- a/src/quicktemplates/qquickabstractspinbox_p.h +++ b/src/quicktemplates/qquickabstractspinbox_p.h @@ -437,12 +437,12 @@ public: } public: - void increase() + virtual void increase() { d_func()->increase(QQuickAbstractSpinBoxPrivate::ValueStatus::Unmodified); } - void decrease() + virtual void decrease() { d_func()->decrease(QQuickAbstractSpinBoxPrivate::ValueStatus::Unmodified); } diff --git a/src/quicktemplates/qquickdoublespinbox.cpp b/src/quicktemplates/qquickdoublespinbox.cpp index dac7b09f83..fcba668084 100644 --- a/src/quicktemplates/qquickdoublespinbox.cpp +++ b/src/quicktemplates/qquickdoublespinbox.cpp @@ -463,10 +463,20 @@ void QQuickDoubleSpinBox::setWrap(bool wrap) \include qquickspinbox.qdocinc {increase} {DoubleSpinBox} */ +void QQuickDoubleSpinBox::increase() +{ + QQuickAbstractSpinBox<QQuickDoubleSpinBox, double>::increase(); +} + /*! \include qquickspinbox.qdocinc {decrease} {DoubleSpinBox} */ +void QQuickDoubleSpinBox::decrease() +{ + QQuickAbstractSpinBox<QQuickDoubleSpinBox, double>::decrease(); +} + void QQuickDoubleSpinBox::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) { Q_D(QQuickDoubleSpinBox); diff --git a/src/quicktemplates/qquickdoublespinbox_p.h b/src/quicktemplates/qquickdoublespinbox_p.h index 77faf8d8c9..ad3e2f4f87 100644 --- a/src/quicktemplates/qquickdoublespinbox_p.h +++ b/src/quicktemplates/qquickdoublespinbox_p.h @@ -78,6 +78,10 @@ public: void setWrap(bool wrap); +public Q_SLOTS: + void increase() override; + void decrease() override; + Q_SIGNALS: void fromChanged(); void toChanged(); diff --git a/src/quicktemplates/qquickspinbox.cpp b/src/quicktemplates/qquickspinbox.cpp index e5d391e89b..dd6114e661 100644 --- a/src/quicktemplates/qquickspinbox.cpp +++ b/src/quicktemplates/qquickspinbox.cpp @@ -491,10 +491,20 @@ void QQuickSpinBox::setWrap(bool wrap) \include qquickspinbox.qdocinc {increase} {SpinBox} */ +void QQuickSpinBox::increase() +{ + QQuickAbstractSpinBox<QQuickSpinBox, int>::increase(); +} + /*! \include qquickspinbox.qdocinc {decrease} {SpinBox} */ +void QQuickSpinBox::decrease() +{ + QQuickAbstractSpinBox<QQuickSpinBox, int>::decrease(); +} + void QQuickSpinBox::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) { Q_D(QQuickSpinBox); diff --git a/src/quicktemplates/qquickspinbox_p.h b/src/quicktemplates/qquickspinbox_p.h index 0cfc14e28a..9916dafd1b 100644 --- a/src/quicktemplates/qquickspinbox_p.h +++ b/src/quicktemplates/qquickspinbox_p.h @@ -75,6 +75,10 @@ public: void setWrap(bool wrap); +public Q_SLOTS: + void increase() override; + void decrease() override; + Q_SIGNALS: void fromChanged(); void toChanged(); diff --git a/tests/auto/quickcontrols/controls/data/tst_doublespinbox.qml b/tests/auto/quickcontrols/controls/data/tst_doublespinbox.qml index a743dc9f57..83b01ed543 100644 --- a/tests/auto/quickcontrols/controls/data/tst_doublespinbox.qml +++ b/tests/auto/quickcontrols/controls/data/tst_doublespinbox.qml @@ -866,4 +866,14 @@ TestCase { let control = createTemporaryObject(doubleSpinBox, testCase, { validator: null }) verify(control) } + + function test_increaseAndDecrease() { + let control = createTemporaryObject(doubleSpinBox, testCase, {from: 0, to: 100, value: 50}) + verify(control) + compare(control.value, 50) + control.increase() + compare(control.value, 51) + control.decrease() + compare(control.value, 50) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_spinbox.qml b/tests/auto/quickcontrols/controls/data/tst_spinbox.qml index 40a6dd8f72..a8da8807fa 100644 --- a/tests/auto/quickcontrols/controls/data/tst_spinbox.qml +++ b/tests/auto/quickcontrols/controls/data/tst_spinbox.qml @@ -1171,4 +1171,14 @@ TestCase { let control = createTemporaryObject(spinBox, testCase, { validator: null }) verify(control) } + + function test_increaseAndDecrease() { + let control = createTemporaryObject(spinBox, testCase, {from: 0, to: 100, value: 50}) + verify(control) + compare(control.value, 50) + control.increase() + compare(control.value, 51) + control.decrease() + compare(control.value, 50) + } } |
