summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSze Howe Koh <szehowe.koh@gmail.com>2016-09-07 08:15:46 +0800
committerSze Howe Koh <szehowe.koh@gmail.com>2017-03-14 03:29:20 +0000
commit9c5322256604f6870233e6cd57a1a0fe0a6ccb23 (patch)
tree450f7ce2241529a8ab2c4758de26eb743c4b13d5
parent6fe77f0a29431e3943ceb84621e2f5133c2e25d5 (diff)
downloadqtdoc-9c5322256604f6870233e6cd57a1a0fe0a6ccb23.tar.gz
Doc: Update example for connecting overloaded signas/slots
- Demonstrate qOverload(), which was added in Qt 5.7 - Replace QSignalMapper with QLCDNumber, because the former will be deprecated soon Change-Id: I0d5dccb5c6fbff4b3d34d6b5a51a878bdfca7a59 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
-rw-r--r--doc/src/signalslotsyntaxes.qdoc15
-rw-r--r--doc/src/snippets/signalsandslots/signalslotsyntaxes.cpp28
-rw-r--r--doc/src/snippets/signalsandslots/signalslotsyntaxes.pro2
3 files changed, 27 insertions, 18 deletions
diff --git a/doc/src/signalslotsyntaxes.qdoc b/doc/src/signalslotsyntaxes.qdoc
index 546b18c0..14400b43 100644
--- a/doc/src/signalslotsyntaxes.qdoc
+++ b/doc/src/signalslotsyntaxes.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2014 Sze Howe Koh <szehowe.koh@gmail.com>
+** Copyright (C) 2017 Sze Howe Koh <szehowe.koh@gmail.com>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
@@ -192,16 +192,17 @@ result, the desired instance of an overloaded signal or slot is unambiguous.
In contrast, with the functor-based syntax, an overloaded signal or slot must
be casted to tell the compiler which instance to use.
-For example, \l QSignalMapper has four versions of the \c mapped() signal:
+For example, \l QLCDNumber has three versions of the \c display() slot:
\list 1
-\li \c QSignalMapper::mapped(int)
-\li \c QSignalMapper::mapped(QString)
-\li \c QSignalMapper::mapped(QWidget*)
-\li \c QSignalMapper::mapped(QObject*)
+\li \c QLCDNumber::display(int)
+\li \c QLCDNumber::display(double)
+\li \c QLCDNumber::display(QString)
\endlist
-To connect the \c int version to QSpinBox::setValue(), the two syntaxes are:
+To connect the \c int version to QSlider::valueChanged(), the two syntaxes are:
\snippet snippets/signalsandslots/signalslotsyntaxes.cpp overload
+\sa qOverload()
+
*/
diff --git a/doc/src/snippets/signalsandslots/signalslotsyntaxes.cpp b/doc/src/snippets/signalsandslots/signalslotsyntaxes.cpp
index dbdec712..a6d9aa6f 100644
--- a/doc/src/snippets/signalsandslots/signalslotsyntaxes.cpp
+++ b/doc/src/snippets/signalsandslots/signalslotsyntaxes.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2014 Sze Howe Koh <szehowe.koh@gmail.com>
+** Copyright (C) 2017 Sze Howe Koh <szehowe.koh@gmail.com>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
@@ -136,20 +136,28 @@ DemoWidget::DemoWidget(QWidget *parent) : QWidget(parent) {
void DemoWidget::demoOverloadConnect()
{
//! [overload]
- auto mapper = new QSignalMapper(this);
- auto spinBox = new QSpinBox(this);
+ auto slider = new QSlider(this);
+ auto lcd = new QLCDNumber(this);
// String-based syntax
- connect(mapper, SIGNAL(mapped(int)),
- spinBox, SLOT(setValue(int)));
+ connect(slider, SIGNAL(valueChanged(int)),
+ lcd, SLOT(display(int)));
// Functor-based syntax, first alternative
- connect(mapper, static_cast<void (QSignalMapper::*)(int)>(&QSignalMapper::mapped),
- spinBox, &QSpinBox::setValue);
+ connect(slider, &QSlider::valueChanged,
+ lcd, static_cast<void (QLCDNumber::*)(int)>(&QLCDNumber::display));
// Functor-based syntax, second alternative
- void (QSignalMapper::*mySignal)(int) = &QSignalMapper::mapped;
- connect(mapper, mySignal,
- spinBox, &QSpinBox::setValue);
+ void (QLCDNumber::*mySlot)(int) = &QLCDNumber::display;
+ connect(slider, &QSlider::valueChanged,
+ lcd, mySlot);
+
+ // Functor-based syntax, third alternative
+ connect(slider, &QSlider::valueChanged,
+ lcd, QOverload<int>::of(&QLCDNumber::display));
+
+ // Functor-based syntax, fourth alternative (requires C++14)
+ connect(slider, &QSlider::valueChanged,
+ lcd, qOverload<int>(&QLCDNumber::display));
//! [overload]
}
diff --git a/doc/src/snippets/signalsandslots/signalslotsyntaxes.pro b/doc/src/snippets/signalsandslots/signalslotsyntaxes.pro
index 1350c9f3..b3b1b9be 100644
--- a/doc/src/snippets/signalsandslots/signalslotsyntaxes.pro
+++ b/doc/src/snippets/signalsandslots/signalslotsyntaxes.pro
@@ -1,5 +1,5 @@
QT += widgets quickwidgets multimedia
-CONFIG += c++11
+CONFIG += c++14
HEADERS = signalslotsyntaxes.h
SOURCES = signalslotsyntaxes.cpp
OTHER_FILES = QmlGui.qml