diff options
author | Alexander Volkov <a.volkov@rusbitech.ru> | 2016-12-20 21:37:37 +0300 |
---|---|---|
committer | Alexander Volkov <a.volkov@rusbitech.ru> | 2016-12-22 14:54:55 +0000 |
commit | fb7bfbf18d91d0bd0f1c88ee6043e3dfa7ae9b9e (patch) | |
tree | 4afb53415fdd372095f3e9abcb7e9f332d01be40 /examples/widgets/widgets | |
parent | 63e7ff97e960987080e6bda668ba960650dca87f (diff) |
examples: Use QOverload to select overloaded signals and slots
We can use QOverload since Qt 5.7 (it depends on Q_COMPILER_VARIADIC_TEMPLATES
which is required since Qt 5.7).
Use it in the examples to show the best practice.
qOverload currently can't be used because it requires c++14.
Change-Id: I94a3c0db9d551fe169fa3d19c07ec0b329d5946c
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'examples/widgets/widgets')
-rw-r--r-- | examples/widgets/widgets/charactermap/mainwindow.cpp | 8 | ||||
-rw-r--r-- | examples/widgets/widgets/icons/imagedelegate.cpp | 3 | ||||
-rw-r--r-- | examples/widgets/widgets/icons/mainwindow.cpp | 6 |
3 files changed, 6 insertions, 11 deletions
diff --git a/examples/widgets/widgets/charactermap/mainwindow.cpp b/examples/widgets/widgets/charactermap/mainwindow.cpp index 8b406ba1ca..5f17128a2f 100644 --- a/examples/widgets/widgets/charactermap/mainwindow.cpp +++ b/examples/widgets/widgets/charactermap/mainwindow.cpp @@ -74,8 +74,7 @@ MainWindow::MainWindow() filterCombo->addItem(tr("Monospaced"), QVariant::fromValue(QFontComboBox::MonospacedFonts)); filterCombo->addItem(tr("Proportional"), QVariant::fromValue(QFontComboBox::ProportionalFonts)); filterCombo->setCurrentIndex(0); - typedef void (QComboBox::*QComboBoxIntSignal)(int); - connect(filterCombo, static_cast<QComboBoxIntSignal>(&QComboBox::currentIndexChanged), + connect(filterCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::filterChanged); QLabel *fontLabel = new QLabel(tr("Font:")); @@ -114,10 +113,9 @@ MainWindow::MainWindow() this, &MainWindow::findSizes); connect(fontCombo, &QFontComboBox::currentFontChanged, characterWidget, &CharacterWidget::updateFont); - typedef void (QComboBox::*QComboBoxStringSignal)(const QString &); - connect(sizeCombo, static_cast<QComboBoxStringSignal>(&QComboBox::currentIndexChanged), + connect(sizeCombo, QOverload<const QString &>::of(&QComboBox::currentIndexChanged), characterWidget, &CharacterWidget::updateSize); - connect(styleCombo, static_cast<QComboBoxStringSignal>(&QComboBox::currentIndexChanged), + connect(styleCombo, QOverload<const QString &>::of(&QComboBox::currentIndexChanged), characterWidget, &CharacterWidget::updateStyle); //! [4] //! [5] connect(characterWidget, &CharacterWidget::characterSelected, diff --git a/examples/widgets/widgets/icons/imagedelegate.cpp b/examples/widgets/widgets/icons/imagedelegate.cpp index 980013daee..3c873f1e24 100644 --- a/examples/widgets/widgets/icons/imagedelegate.cpp +++ b/examples/widgets/widgets/icons/imagedelegate.cpp @@ -71,8 +71,7 @@ QWidget *ImageDelegate::createEditor(QWidget *parent, else if (index.column() == 2) comboBox->addItems(IconPreviewArea::iconStateNames()); - typedef void (QComboBox::*QComboBoxIntSignal)(int); - connect(comboBox, static_cast<QComboBoxIntSignal>(&QComboBox::activated), + connect(comboBox, QOverload<int>::of(&QComboBox::activated), this, &ImageDelegate::emitCommitData); return comboBox; diff --git a/examples/widgets/widgets/icons/mainwindow.cpp b/examples/widgets/widgets/icons/mainwindow.cpp index 5f3882de94..f704b8306f 100644 --- a/examples/widgets/widgets/icons/mainwindow.cpp +++ b/examples/widgets/widgets/icons/mainwindow.cpp @@ -362,8 +362,7 @@ QWidget *MainWindow::createIconSizeGroupBox() sizeButtonGroup = new QButtonGroup(this); sizeButtonGroup->setExclusive(true); - typedef void (QButtonGroup::*QButtonGroupIntBoolSignal)(int, bool); - connect(sizeButtonGroup, static_cast<QButtonGroupIntBoolSignal>(&QButtonGroup::buttonToggled), + connect(sizeButtonGroup, QOverload<int, bool>::of(&QButtonGroup::buttonToggled), this, &MainWindow::changeSize); QRadioButton *smallRadioButton = new QRadioButton; @@ -391,8 +390,7 @@ QWidget *MainWindow::createIconSizeGroupBox() //! [26] //! [27] - typedef void (QSpinBox::*QSpinBoxIntSignal)(int); - connect(otherSpinBox, static_cast<QSpinBoxIntSignal>(&QSpinBox::valueChanged), + connect(otherSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &MainWindow::triggerChangeSize); QHBoxLayout *otherSizeLayout = new QHBoxLayout; |