From fb7bfbf18d91d0bd0f1c88ee6043e3dfa7ae9b9e Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Tue, 20 Dec 2016 21:37:37 +0300 Subject: 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 Reviewed-by: Olivier Goffart (Woboq GmbH) --- examples/opengl/qopenglwidget/mainwindow.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'examples/opengl/qopenglwidget/mainwindow.cpp') diff --git a/examples/opengl/qopenglwidget/mainwindow.cpp b/examples/opengl/qopenglwidget/mainwindow.cpp index f602c9995b..1bb2aa2bf0 100644 --- a/examples/opengl/qopenglwidget/mainwindow.cpp +++ b/examples/opengl/qopenglwidget/mainwindow.cpp @@ -61,8 +61,6 @@ #include "glwidget.h" -typedef void (QWidget::*QWidgetVoidSlot)(); - MainWindow::MainWindow() : m_nextX(1), m_nextY(1) { @@ -131,14 +129,11 @@ MainWindow::MainWindow() QMenu *helpMenu = menuBar()->addMenu("&Help"); helpMenu->addAction("About Qt", qApp, &QApplication::aboutQt); - connect(m_timer, &QTimer::timeout, - glwidget, static_cast(&QWidget::update)); + connect(m_timer, &QTimer::timeout, glwidget, QOverload<>::of(&QWidget::update)); connect(slider, &QAbstractSlider::valueChanged, glwidget, &GLWidget::setScaling); connect(transparent, &QCheckBox::toggled, glwidget, &GLWidget::setTransparent); - - typedef void (QSpinBox::*QSpinBoxIntSignal)(int); - connect(updateInterval, static_cast(&QSpinBox::valueChanged), + connect(updateInterval, QOverload::of(&QSpinBox::valueChanged), this, &MainWindow::updateIntervalChanged); connect(timerBased, &QCheckBox::toggled, this, &MainWindow::timerUsageChanged); connect(timerBased, &QCheckBox::toggled, updateInterval, &QWidget::setEnabled); @@ -162,7 +157,7 @@ void MainWindow::addNew() return; GLWidget *w = new GLWidget(this, false, qRgb(qrand() % 256, qrand() % 256, qrand() % 256)); m_glWidgets << w; - connect(m_timer, &QTimer::timeout, w, static_cast(&QWidget::update)); + connect(m_timer, &QTimer::timeout, w, QOverload<>::of(&QWidget::update)); m_layout->addWidget(w, m_nextY, m_nextX, 1, 1); if (m_nextX == 3) { m_nextX = 1; -- cgit v1.2.3