From 8c04aab8966611e96c64f469b7a1c6afe67e3fca Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 7 Dec 2018 14:17:38 +0100 Subject: Cleanup Widgets examples - new signal/slot syntax Cleanup the Widget examples - use the new signal/slot syntax where possible - layout, statemachine, tools and touch subdirectory Change-Id: I466b309b643ef7ffc27be7591fa10f4c75cfd3f8 Reviewed-by: Luca Beldi Reviewed-by: Sze Howe Koh Reviewed-by: Paul Wicking --- examples/widgets/layouts/basiclayouts/dialog.cpp | 6 +-- examples/widgets/statemachine/factorial/main.cpp | 4 +- examples/widgets/statemachine/rogue/window.cpp | 3 +- .../widgets/statemachine/trafficlight/main.cpp | 16 +++---- .../widgets/statemachine/twowaybutton/main.cpp | 4 +- examples/widgets/tools/completer/mainwindow.cpp | 20 +++++---- .../widgets/tools/customcompleter/mainwindow.cpp | 6 +-- .../widgets/tools/customcompleter/textedit.cpp | 4 +- examples/widgets/tools/regexp/regexpdialog.cpp | 18 ++++---- .../tools/treemodelcompleter/mainwindow.cpp | 26 +++++------ examples/widgets/tools/undo/mainwindow.cpp | 50 +++++++++++----------- .../widgets/tools/undoframework/mainwindow.cpp | 22 +++++----- examples/widgets/touch/fingerpaint/mainwindow.cpp | 16 +++---- 13 files changed, 101 insertions(+), 94 deletions(-) (limited to 'examples/widgets') diff --git a/examples/widgets/layouts/basiclayouts/dialog.cpp b/examples/widgets/layouts/basiclayouts/dialog.cpp index 7acbc50eb7..8376820545 100644 --- a/examples/widgets/layouts/basiclayouts/dialog.cpp +++ b/examples/widgets/layouts/basiclayouts/dialog.cpp @@ -69,8 +69,8 @@ Dialog::Dialog() buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); - connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); //! [1] //! [2] @@ -99,7 +99,7 @@ void Dialog::createMenu() exitAction = fileMenu->addAction(tr("E&xit")); menuBar->addMenu(fileMenu); - connect(exitAction, SIGNAL(triggered()), this, SLOT(accept())); + connect(exitAction, &QAction::triggered, this, &QDialog::accept); } //! [6] diff --git a/examples/widgets/statemachine/factorial/main.cpp b/examples/widgets/statemachine/factorial/main.cpp index f100aa0110..2d25822828 100644 --- a/examples/widgets/statemachine/factorial/main.cpp +++ b/examples/widgets/statemachine/factorial/main.cpp @@ -100,7 +100,7 @@ class FactorialLoopTransition : public QSignalTransition { public: FactorialLoopTransition(Factorial *fact) - : QSignalTransition(fact, SIGNAL(xChanged(int))), m_fact(fact) + : QSignalTransition(fact, &Factorial::xChanged), m_fact(fact) {} bool eventTest(QEvent *e) override @@ -130,7 +130,7 @@ class FactorialDoneTransition : public QSignalTransition { public: FactorialDoneTransition(Factorial *fact) - : QSignalTransition(fact, SIGNAL(xChanged(int))), m_fact(fact) + : QSignalTransition(fact, &Factorial::xChanged), m_fact(fact) {} bool eventTest(QEvent *e) override diff --git a/examples/widgets/statemachine/rogue/window.cpp b/examples/widgets/statemachine/rogue/window.cpp index 059fbf1003..f91a6e522e 100644 --- a/examples/widgets/statemachine/rogue/window.cpp +++ b/examples/widgets/statemachine/rogue/window.cpp @@ -217,7 +217,8 @@ void Window::buildMachine() //![5] machine->setInitialState(inputState); - connect(machine, SIGNAL(finished()), qApp, SLOT(quit())); + connect(machine, &QStateMachine::finished, + qApp, &QApplication::quit); machine->start(); } diff --git a/examples/widgets/statemachine/trafficlight/main.cpp b/examples/widgets/statemachine/trafficlight/main.cpp index 21df91d8b0..b348d4f65d 100644 --- a/examples/widgets/statemachine/trafficlight/main.cpp +++ b/examples/widgets/statemachine/trafficlight/main.cpp @@ -132,11 +132,11 @@ QState *createLightState(LightWidget *light, int duration, QState *parent = 0) timer->setInterval(duration); timer->setSingleShot(true); QState *timing = new QState(lightState); - QObject::connect(timing, SIGNAL(entered()), light, SLOT(turnOn())); - QObject::connect(timing, SIGNAL(entered()), timer, SLOT(start())); - QObject::connect(timing, SIGNAL(exited()), light, SLOT(turnOff())); + QObject::connect(timing, &QAbstractState::entered, light, &LightWidget::turnOn); + QObject::connect(timing, &QAbstractState::entered, timer, QOverload<>::of(&QTimer::start)); + QObject::connect(timing, &QAbstractState::exited, light, &LightWidget::turnOff); QFinalState *done = new QFinalState(lightState); - timing->addTransition(timer, SIGNAL(timeout()), done); + timing->addTransition(timer, &QTimer::timeout, done); lightState->setInitialState(timing); return lightState; } @@ -159,14 +159,14 @@ public: redGoingYellow->setObjectName("redGoingYellow"); QState *yellowGoingGreen = createLightState(widget->yellowLight(), 1000); yellowGoingGreen->setObjectName("yellowGoingGreen"); - redGoingYellow->addTransition(redGoingYellow, SIGNAL(finished()), yellowGoingGreen); + redGoingYellow->addTransition(redGoingYellow, &QState::finished, yellowGoingGreen); QState *greenGoingYellow = createLightState(widget->greenLight(), 3000); greenGoingYellow->setObjectName("greenGoingYellow"); - yellowGoingGreen->addTransition(yellowGoingGreen, SIGNAL(finished()), greenGoingYellow); + yellowGoingGreen->addTransition(yellowGoingGreen, &QState::finished, greenGoingYellow); QState *yellowGoingRed = createLightState(widget->yellowLight(), 1000); yellowGoingRed->setObjectName("yellowGoingRed"); - greenGoingYellow->addTransition(greenGoingYellow, SIGNAL(finished()), yellowGoingRed); - yellowGoingRed->addTransition(yellowGoingRed, SIGNAL(finished()), redGoingYellow); + greenGoingYellow->addTransition(greenGoingYellow, &QState::finished, yellowGoingRed); + yellowGoingRed->addTransition(yellowGoingRed, &QState::finished, redGoingYellow); machine->addState(redGoingYellow); machine->addState(yellowGoingGreen); diff --git a/examples/widgets/statemachine/twowaybutton/main.cpp b/examples/widgets/statemachine/twowaybutton/main.cpp index 5c778aba70..3d4fef3bbe 100644 --- a/examples/widgets/statemachine/twowaybutton/main.cpp +++ b/examples/widgets/statemachine/twowaybutton/main.cpp @@ -69,8 +69,8 @@ int main(int argc, char **argv) //! [1] //! [2] - off->addTransition(&button, SIGNAL(clicked()), on); - on->addTransition(&button, SIGNAL(clicked()), off); + off->addTransition(&button, &QAbstractButton::clicked, on); + on->addTransition(&button, &QAbstractButton::clicked, off); //! [2] //! [3] diff --git a/examples/widgets/tools/completer/mainwindow.cpp b/examples/widgets/tools/completer/mainwindow.cpp index 8eb2e60030..114ff0fd7c 100644 --- a/examples/widgets/tools/completer/mainwindow.cpp +++ b/examples/widgets/tools/completer/mainwindow.cpp @@ -102,10 +102,14 @@ MainWindow::MainWindow(QWidget *parent) contentsLabel = new QLabel; contentsLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - connect(modelCombo, SIGNAL(activated(int)), this, SLOT(changeModel())); - connect(modeCombo, SIGNAL(activated(int)), this, SLOT(changeMode(int))); - connect(caseCombo, SIGNAL(activated(int)), this, SLOT(changeCase(int))); - connect(maxVisibleSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeMaxVisible(int))); + connect(modelCombo, QOverload::of(&QComboBox::activated), + this, &MainWindow::changeModel); + connect(modeCombo, QOverload::of(&QComboBox::activated), + this, &MainWindow::changeMode); + connect(caseCombo, QOverload::of(&QComboBox::activated), + this, &MainWindow::changeCase); + connect(maxVisibleSpinBox, QOverload::of(&QSpinBox::valueChanged), + this, &MainWindow::changeMaxVisible); //! [2] //! [3] @@ -136,9 +140,9 @@ void MainWindow::createMenu() QAction *aboutAct = new QAction(tr("About"), this); QAction *aboutQtAct = new QAction(tr("About Qt"), this); - connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); - connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); - connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + connect(exitAction, &QAction::triggered, qApp, &QApplication::quit); + connect(aboutAct, &QAction::triggered, this, &MainWindow::about); + connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt); QMenu* fileMenu = menuBar()->addMenu(tr("File")); fileMenu->addAction(exitAction); @@ -271,7 +275,7 @@ void MainWindow::changeModel() changeCase(caseCombo->currentIndex()); completer->setWrapAround(wrapCheckBox->isChecked()); lineEdit->setCompleter(completer); - connect(wrapCheckBox, SIGNAL(clicked(bool)), completer, SLOT(setWrapAround(bool))); + connect(wrapCheckBox, &QAbstractButton::clicked, completer, &QCompleter::setWrapAround); } //! [14] diff --git a/examples/widgets/tools/customcompleter/mainwindow.cpp b/examples/widgets/tools/customcompleter/mainwindow.cpp index 7b9db708b9..39f5f39617 100644 --- a/examples/widgets/tools/customcompleter/mainwindow.cpp +++ b/examples/widgets/tools/customcompleter/mainwindow.cpp @@ -79,9 +79,9 @@ void MainWindow::createMenu() QAction *aboutAct = new QAction(tr("About"), this); QAction *aboutQtAct = new QAction(tr("About Qt"), this); - connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); - connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); - connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + connect(exitAction, &QAction::triggered, qApp, &QApplication::quit); + connect(aboutAct, &QAction::triggered, this, &MainWindow::about); + connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt); QMenu* fileMenu = menuBar()->addMenu(tr("File")); fileMenu->addAction(exitAction); diff --git a/examples/widgets/tools/customcompleter/textedit.cpp b/examples/widgets/tools/customcompleter/textedit.cpp index 5512e72843..d42f7b38bb 100644 --- a/examples/widgets/tools/customcompleter/textedit.cpp +++ b/examples/widgets/tools/customcompleter/textedit.cpp @@ -88,8 +88,8 @@ void TextEdit::setCompleter(QCompleter *completer) c->setWidget(this); c->setCompletionMode(QCompleter::PopupCompletion); c->setCaseSensitivity(Qt::CaseInsensitive); - QObject::connect(c, SIGNAL(activated(QString)), - this, SLOT(insertCompletion(QString))); + QObject::connect(c, QOverload::of(&QCompleter::activated), + this, &TextEdit::insertCompletion); } //! [2] diff --git a/examples/widgets/tools/regexp/regexpdialog.cpp b/examples/widgets/tools/regexp/regexpdialog.cpp index 7b3fee5794..bf61d09974 100644 --- a/examples/widgets/tools/regexp/regexpdialog.cpp +++ b/examples/widgets/tools/regexp/regexpdialog.cpp @@ -135,15 +135,15 @@ RegExpDialog::RegExpDialog(QWidget *parent) } setLayout(mainLayout); - connect(patternComboBox, SIGNAL(editTextChanged(QString)), - this, SLOT(refresh())); - connect(textComboBox, SIGNAL(editTextChanged(QString)), - this, SLOT(refresh())); - connect(caseSensitiveCheckBox, SIGNAL(toggled(bool)), - this, SLOT(refresh())); - connect(minimalCheckBox, SIGNAL(toggled(bool)), this, SLOT(refresh())); - connect(syntaxComboBox, SIGNAL(currentIndexChanged(int)), - this, SLOT(refresh())); + connect(patternComboBox, &QComboBox::editTextChanged, + this, &RegExpDialog::refresh); + connect(textComboBox, &QComboBox::editTextChanged, + this, &RegExpDialog::refresh); + connect(caseSensitiveCheckBox, &QAbstractButton::toggled, + this, &RegExpDialog::refresh); + connect(minimalCheckBox, &QAbstractButton::toggled, this, &RegExpDialog::refresh); + connect(syntaxComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, &RegExpDialog::refresh); patternComboBox->addItem(tr("[A-Za-z_]+([A-Za-z_0-9]*)")); textComboBox->addItem(tr("(10 + delta4) * 32")); diff --git a/examples/widgets/tools/treemodelcompleter/mainwindow.cpp b/examples/widgets/tools/treemodelcompleter/mainwindow.cpp index 72b2fad833..dec3cb0496 100644 --- a/examples/widgets/tools/treemodelcompleter/mainwindow.cpp +++ b/examples/widgets/tools/treemodelcompleter/mainwindow.cpp @@ -61,8 +61,8 @@ MainWindow::MainWindow(QWidget *parent) completer = new TreeModelCompleter(this); completer->setModel(modelFromFile(":/resources/treemodel.txt")); completer->setSeparator(QLatin1String(".")); - QObject::connect(completer, SIGNAL(highlighted(QModelIndex)), - this, SLOT(highlight(QModelIndex))); + QObject::connect(completer, QOverload::of(&TreeModelCompleter::highlighted), + this, &MainWindow::highlight); QWidget *centralWidget = new QWidget; @@ -91,18 +91,18 @@ MainWindow::MainWindow(QWidget *parent) QLineEdit *separatorLineEdit = new QLineEdit; separatorLineEdit->setText(completer->separator()); - connect(separatorLineEdit, SIGNAL(textChanged(QString)), - completer, SLOT(setSeparator(QString))); + connect(separatorLineEdit, &QLineEdit::textChanged, + completer, &TreeModelCompleter::setSeparator); QCheckBox *wrapCheckBox = new QCheckBox; wrapCheckBox->setText(tr("Wrap around completions")); wrapCheckBox->setChecked(completer->wrapAround()); - connect(wrapCheckBox, SIGNAL(clicked(bool)), completer, SLOT(setWrapAround(bool))); + connect(wrapCheckBox, &QAbstractButton::clicked, completer, &QCompleter::setWrapAround); contentsLabel = new QLabel; contentsLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - connect(separatorLineEdit, SIGNAL(textChanged(QString)), - this, SLOT(updateContentsLabel(QString))); + connect(separatorLineEdit, &QLineEdit::textChanged, + this, &MainWindow::updateContentsLabel); treeView = new QTreeView; treeView->setModel(completer->model()); @@ -111,8 +111,10 @@ MainWindow::MainWindow(QWidget *parent) //! [1] //! [2] - connect(modeCombo, SIGNAL(activated(int)), this, SLOT(changeMode(int))); - connect(caseCombo, SIGNAL(activated(int)), this, SLOT(changeCase(int))); + connect(modeCombo, QOverload::of(&QComboBox::activated), + this, &MainWindow::changeMode); + connect(caseCombo, QOverload::of(&QComboBox::activated), + this, &MainWindow::changeMode); lineEdit = new QLineEdit; lineEdit->setCompleter(completer); @@ -145,9 +147,9 @@ void MainWindow::createMenu() QAction *aboutAct = new QAction(tr("About"), this); QAction *aboutQtAct = new QAction(tr("About Qt"), this); - connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); - connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); - connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + connect(exitAction, &QAction::triggered, qApp, &QApplication::quit); + connect(aboutAct, &QAction::triggered, this, &MainWindow::about); + connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt); QMenu* fileMenu = menuBar()->addMenu(tr("File")); fileMenu->addAction(exitAction); diff --git a/examples/widgets/tools/undo/mainwindow.cpp b/examples/widgets/tools/undo/mainwindow.cpp index 5976163f3f..118d604742 100644 --- a/examples/widgets/tools/undo/mainwindow.cpp +++ b/examples/widgets/tools/undo/mainwindow.cpp @@ -68,25 +68,25 @@ MainWindow::MainWindow(QWidget *parent) documentTabs->removeTab(0); delete w; - connect(actionOpen, SIGNAL(triggered()), this, SLOT(openDocument())); - connect(actionClose, SIGNAL(triggered()), this, SLOT(closeDocument())); - connect(actionNew, SIGNAL(triggered()), this, SLOT(newDocument())); - connect(actionSave, SIGNAL(triggered()), this, SLOT(saveDocument())); - connect(actionExit, SIGNAL(triggered()), this, SLOT(close())); - connect(actionRed, SIGNAL(triggered()), this, SLOT(setShapeColor())); - connect(actionGreen, SIGNAL(triggered()), this, SLOT(setShapeColor())); - connect(actionBlue, SIGNAL(triggered()), this, SLOT(setShapeColor())); - connect(actionAddCircle, SIGNAL(triggered()), this, SLOT(addShape())); - connect(actionAddRectangle, SIGNAL(triggered()), this, SLOT(addShape())); - connect(actionAddTriangle, SIGNAL(triggered()), this, SLOT(addShape())); - connect(actionRemoveShape, SIGNAL(triggered()), this, SLOT(removeShape())); - connect(actionAddRobot, SIGNAL(triggered()), this, SLOT(addRobot())); - connect(actionAddSnowman, SIGNAL(triggered()), this, SLOT(addSnowman())); - connect(actionAbout, SIGNAL(triggered()), this, SLOT(about())); - connect(actionAboutQt, SIGNAL(triggered()), this, SLOT(aboutQt())); - - connect(undoLimit, SIGNAL(valueChanged(int)), this, SLOT(updateActions())); - connect(documentTabs, SIGNAL(currentChanged(int)), this, SLOT(updateActions())); + connect(actionOpen, &QAction::triggered, this, &MainWindow::openDocument); + connect(actionClose, &QAction::triggered, this, &MainWindow::closeDocument); + connect(actionNew, &QAction::triggered, this, &MainWindow::newDocument); + connect(actionSave, &QAction::triggered, this, &MainWindow::saveDocument); + connect(actionExit, &QAction::triggered, this, &QWidget::close); + connect(actionRed, &QAction::triggered, this, &MainWindow::setShapeColor); + connect(actionGreen, &QAction::triggered, this, &MainWindow::setShapeColor); + connect(actionBlue, &QAction::triggered, this, &MainWindow::setShapeColor); + connect(actionAddCircle, &QAction::triggered, this, &MainWindow::addShape); + connect(actionAddRectangle, &QAction::triggered, this, &MainWindow::addShape); + connect(actionAddTriangle, &QAction::triggered, this, &MainWindow::addShape); + connect(actionRemoveShape, &QAction::triggered, this, &MainWindow::removeShape); + connect(actionAddRobot, &QAction::triggered, this, &MainWindow::addRobot); + connect(actionAddSnowman, &QAction::triggered, this, &MainWindow::addSnowman); + connect(actionAbout, &QAction::triggered, this, &MainWindow::about); + connect(actionAboutQt, &QAction::triggered, this, &MainWindow::aboutQt); + + connect(undoLimit, QOverload::of(&QSpinBox::valueChanged), this, &MainWindow::updateActions); + connect(documentTabs, &QTabWidget::currentChanged, this, &MainWindow::updateActions); actionOpen->setShortcut(QString("Ctrl+O")); actionClose->setShortcut(QString("Ctrl+W")); @@ -226,9 +226,9 @@ void MainWindow::addDocument(Document *doc) return; m_undoGroup->addStack(doc->undoStack()); documentTabs->addTab(doc, fixedWindowTitle(doc)); - connect(doc, SIGNAL(currentShapeChanged(QString)), this, SLOT(updateActions())); - connect(doc->undoStack(), SIGNAL(indexChanged(int)), this, SLOT(updateActions())); - connect(doc->undoStack(), SIGNAL(cleanChanged(bool)), this, SLOT(updateActions())); + connect(doc, &Document::currentShapeChanged, this, &MainWindow::updateActions); + connect(doc->undoStack(), &QUndoStack::indexChanged, this, &MainWindow::updateActions); + connect(doc->undoStack(), &QUndoStack::cleanChanged, this, &MainWindow::updateActions); setCurrentDocument(doc); } @@ -251,9 +251,9 @@ void MainWindow::removeDocument(Document *doc) documentTabs->removeTab(index); m_undoGroup->removeStack(doc->undoStack()); - disconnect(doc, SIGNAL(currentShapeChanged(QString)), this, SLOT(updateActions())); - disconnect(doc->undoStack(), SIGNAL(indexChanged(int)), this, SLOT(updateActions())); - disconnect(doc->undoStack(), SIGNAL(cleanChanged(bool)), this, SLOT(updateActions())); + disconnect(doc, &Document::currentShapeChanged, this, &MainWindow::updateActions); + disconnect(doc->undoStack(), &QUndoStack::indexChanged, this, &MainWindow::updateActions); + disconnect(doc->undoStack(), &QUndoStack::cleanChanged, this, &MainWindow::updateActions); if (documentTabs->count() == 0) { newDocument(); diff --git a/examples/widgets/tools/undoframework/mainwindow.cpp b/examples/widgets/tools/undoframework/mainwindow.cpp index b2f5405b73..e95d50d164 100644 --- a/examples/widgets/tools/undoframework/mainwindow.cpp +++ b/examples/widgets/tools/undoframework/mainwindow.cpp @@ -70,8 +70,8 @@ MainWindow::MainWindow() diagramScene->setBackgroundBrush(pixmapBrush); diagramScene->setSceneRect(QRect(0, 0, 500, 500)); - connect(diagramScene, SIGNAL(itemMoved(DiagramItem*,QPointF)), - this, SLOT(itemMoved(DiagramItem*,QPointF))); + connect(diagramScene, &DiagramScene::itemMoved, + this, &MainWindow::itemMoved); setWindowTitle("Undo Framework"); QGraphicsView *view = new QGraphicsView(diagramScene); @@ -95,18 +95,18 @@ void MainWindow::createActions() { deleteAction = new QAction(tr("&Delete Item"), this); deleteAction->setShortcut(tr("Del")); - connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem())); + connect(deleteAction, &QAction::triggered, this, &MainWindow::deleteItem); //! [2] //! [3] //! [3] //! [4] addBoxAction = new QAction(tr("Add &Box"), this); //! [4] addBoxAction->setShortcut(tr("Ctrl+O")); - connect(addBoxAction, SIGNAL(triggered()), this, SLOT(addBox())); + connect(addBoxAction, &QAction::triggered, this, &MainWindow::addBox); addTriangleAction = new QAction(tr("Add &Triangle"), this); addTriangleAction->setShortcut(tr("Ctrl+T")); - connect(addTriangleAction, SIGNAL(triggered()), this, SLOT(addTriangle())); + connect(addTriangleAction, &QAction::triggered, this, &MainWindow::addTriangle); //! [5] undoAction = undoStack->createUndoAction(this, tr("&Undo")); @@ -118,13 +118,13 @@ void MainWindow::createActions() exitAction = new QAction(tr("E&xit"), this); exitAction->setShortcuts(QKeySequence::Quit); - connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(exitAction, &QAction::triggered, this, &QWidget::close); aboutAction = new QAction(tr("&About"), this); QList aboutShortcuts; aboutShortcuts << tr("Ctrl+A") << tr("Ctrl+B"); aboutAction->setShortcuts(aboutShortcuts); - connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); + connect(aboutAction, &QAction::triggered, this, &MainWindow::about); } //! [6] @@ -140,10 +140,10 @@ void MainWindow::createMenus() editMenu->addAction(redoAction); editMenu->addSeparator(); editMenu->addAction(deleteAction); - connect(editMenu, SIGNAL(aboutToShow()), - this, SLOT(itemMenuAboutToShow())); - connect(editMenu, SIGNAL(aboutToHide()), - this, SLOT(itemMenuAboutToHide())); + connect(editMenu, &QMenu::aboutToShow, + this, &MainWindow::itemMenuAboutToShow); + connect(editMenu, &QMenu::aboutToHide, + this, &MainWindow::itemMenuAboutToHide); //! [7] itemMenu = menuBar()->addMenu(tr("&Item")); diff --git a/examples/widgets/touch/fingerpaint/mainwindow.cpp b/examples/widgets/touch/fingerpaint/mainwindow.cpp index 0e45eea240..b0d91d25bf 100644 --- a/examples/widgets/touch/fingerpaint/mainwindow.cpp +++ b/examples/widgets/touch/fingerpaint/mainwindow.cpp @@ -127,34 +127,34 @@ void MainWindow::createActions() { openAct = new QAction(tr("&Open..."), this); openAct->setShortcut(tr("Ctrl+O")); - connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + connect(openAct, &QAction::triggered, this, &MainWindow::open); foreach (QByteArray format, QImageWriter::supportedImageFormats()) { QString text = tr("%1...").arg(QString(format).toUpper()); QAction *action = new QAction(text, this); action->setData(format); - connect(action, SIGNAL(triggered()), this, SLOT(save())); + connect(action, &QAction::triggered, this, &MainWindow::save); saveAsActs.append(action); } printAct = new QAction(tr("&Print..."), this); - connect(printAct, SIGNAL(triggered()), scribbleArea, SLOT(print())); + connect(printAct, &QAction::triggered, scribbleArea, &ScribbleArea::print); exitAct = new QAction(tr("E&xit"), this); exitAct->setShortcut(tr("Ctrl+Q")); - connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + connect(exitAct, &QAction::triggered, this, &QWidget::close); clearScreenAct = new QAction(tr("&Clear Screen"), this); clearScreenAct->setShortcut(tr("Ctrl+L")); - connect(clearScreenAct, SIGNAL(triggered()), - scribbleArea, SLOT(clearImage())); + connect(clearScreenAct, &QAction::triggered, + scribbleArea, &ScribbleArea::clearImage); aboutAct = new QAction(tr("&About"), this); - connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + connect(aboutAct, &QAction::triggered, this, &MainWindow::about); aboutQtAct = new QAction(tr("About &Qt"), this); - connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt); } //! [14] -- cgit v1.2.3