diff --git a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp index d6a389af38..7588e43701 100644 --- a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp +++ b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp @@ -432,7 +432,7 @@ void MainWindow::createToolbars() fontColorToolButton = new QToolButton; fontColorToolButton->setPopupMode(QToolButton::MenuButtonPopup); - fontColorToolButton->setMenu(createColorMenu(SLOT(textColorChanged()), Qt::black)); + fontColorToolButton->setMenu(createColorMenu(&MainWindow::textColorChanged, Qt::black)); textAction = fontColorToolButton->menu()->defaultAction(); fontColorToolButton->setIcon(createColorToolButtonIcon(":/images/textpointer.png", Qt::black)); fontColorToolButton->setAutoFillBackground(true); @@ -442,7 +442,7 @@ void MainWindow::createToolbars() //! [26] fillColorToolButton = new QToolButton; fillColorToolButton->setPopupMode(QToolButton::MenuButtonPopup); - fillColorToolButton->setMenu(createColorMenu(SLOT(itemColorChanged()), Qt::white)); + fillColorToolButton->setMenu(createColorMenu(&MainWindow::itemColorChanged, Qt::white)); fillAction = fillColorToolButton->menu()->defaultAction(); fillColorToolButton->setIcon(createColorToolButtonIcon( ":/images/floodfill.png", Qt::white)); @@ -452,7 +452,7 @@ void MainWindow::createToolbars() lineColorToolButton = new QToolButton; lineColorToolButton->setPopupMode(QToolButton::MenuButtonPopup); - lineColorToolButton->setMenu(createColorMenu(SLOT(lineColorChanged()), Qt::black)); + lineColorToolButton->setMenu(createColorMenu(&MainWindow::lineColorChanged, Qt::black)); lineAction = lineColorToolButton->menu()->defaultAction(); lineColorToolButton->setIcon(createColorToolButtonIcon( ":/images/linecolor.png", Qt::black)); @@ -547,7 +547,8 @@ QWidget *MainWindow::createCellWidget(const QString &text, DiagramItem::DiagramT //! [29] //! [30] -QMenu *MainWindow::createColorMenu(const char *slot, QColor defaultColor) +template +QMenu *MainWindow::createColorMenu(const PointerToMemberFunction &slot, QColor defaultColor) { QList colors; colors << Qt::black << Qt::white << Qt::red << Qt::blue << Qt::yellow; @@ -560,7 +561,7 @@ QMenu *MainWindow::createColorMenu(const char *slot, QColor defaultColor) QAction *action = new QAction(names.at(i), this); action->setData(colors.at(i)); action->setIcon(createColorIcon(colors.at(i))); - connect(action, SIGNAL(triggered()), this, slot); + connect(action, &QAction::triggered, this, slot); colorMenu->addAction(action); if (colors.at(i) == defaultColor) colorMenu->setDefaultAction(action); diff --git a/examples/widgets/graphicsview/diagramscene/mainwindow.h b/examples/widgets/graphicsview/diagramscene/mainwindow.h index 34f98f6513..fe8a91901f 100644 --- a/examples/widgets/graphicsview/diagramscene/mainwindow.h +++ b/examples/widgets/graphicsview/diagramscene/mainwindow.h @@ -64,7 +64,9 @@ private: const QString &image); QWidget *createCellWidget(const QString &text, DiagramItem::DiagramType type); - QMenu *createColorMenu(const char *slot, QColor defaultColor); + + template + QMenu *createColorMenu(const PointerToMemberFunction &slot, QColor defaultColor); QIcon createColorToolButtonIcon(const QString &image, QColor color); QIcon createColorIcon(QColor color); diff --git a/examples/widgets/painting/pathstroke/pathstroke.cpp b/examples/widgets/painting/pathstroke/pathstroke.cpp index 9bec56233c..8c0548bdf0 100644 --- a/examples/widgets/painting/pathstroke/pathstroke.cpp +++ b/examples/widgets/painting/pathstroke/pathstroke.cpp @@ -341,7 +341,7 @@ PathStrokeWidget::PathStrokeWidget(bool smallScreen) connect(m_renderer, &PathStrokeRenderer::clicked, this, &PathStrokeWidget::showControls); connect(m_controls, &PathStrokeControls::okPressed, this, &PathStrokeWidget::hideControls); - connect(m_controls, SIGNAL(quitPressed()), QApplication::instance(), SLOT(quit())); + connect(m_controls, &PathStrokeControls::quitPressed, QApplication::instance(), &QApplication::quit); } void PathStrokeWidget::showControls() diff --git a/examples/widgets/widgets/calculator/calculator.cpp b/examples/widgets/widgets/calculator/calculator.cpp index 5858d304d2..073b10f985 100644 --- a/examples/widgets/widgets/calculator/calculator.cpp +++ b/examples/widgets/widgets/calculator/calculator.cpp @@ -29,29 +29,29 @@ Calculator::Calculator(QWidget *parent) //! [4] for (int i = 0; i < NumDigitButtons; ++i) - digitButtons[i] = createButton(QString::number(i), SLOT(digitClicked())); + digitButtons[i] = createButton(QString::number(i), &Calculator::digitClicked); - Button *pointButton = createButton(tr("."), SLOT(pointClicked())); - Button *changeSignButton = createButton(tr("\302\261"), SLOT(changeSignClicked())); + Button *pointButton = createButton(tr("."), &Calculator::pointClicked); + Button *changeSignButton = createButton(tr("\302\261"), &Calculator::changeSignClicked); - Button *backspaceButton = createButton(tr("Backspace"), SLOT(backspaceClicked())); - Button *clearButton = createButton(tr("Clear"), SLOT(clear())); - Button *clearAllButton = createButton(tr("Clear All"), SLOT(clearAll())); + Button *backspaceButton = createButton(tr("Backspace"), &Calculator::backspaceClicked); + Button *clearButton = createButton(tr("Clear"), &Calculator::clear); + Button *clearAllButton = createButton(tr("Clear All"), &Calculator::clearAll); - Button *clearMemoryButton = createButton(tr("MC"), SLOT(clearMemory())); - Button *readMemoryButton = createButton(tr("MR"), SLOT(readMemory())); - Button *setMemoryButton = createButton(tr("MS"), SLOT(setMemory())); - Button *addToMemoryButton = createButton(tr("M+"), SLOT(addToMemory())); + Button *clearMemoryButton = createButton(tr("MC"), &Calculator::clearMemory); + Button *readMemoryButton = createButton(tr("MR"), &Calculator::readMemory); + Button *setMemoryButton = createButton(tr("MS"), &Calculator::setMemory); + Button *addToMemoryButton = createButton(tr("M+"), &Calculator::addToMemory); - Button *divisionButton = createButton(tr("\303\267"), SLOT(multiplicativeOperatorClicked())); - Button *timesButton = createButton(tr("\303\227"), SLOT(multiplicativeOperatorClicked())); - Button *minusButton = createButton(tr("-"), SLOT(additiveOperatorClicked())); - Button *plusButton = createButton(tr("+"), SLOT(additiveOperatorClicked())); + Button *divisionButton = createButton(tr("\303\267"), &Calculator::multiplicativeOperatorClicked); + Button *timesButton = createButton(tr("\303\227"), &Calculator::multiplicativeOperatorClicked); + Button *minusButton = createButton(tr("-"), &Calculator::additiveOperatorClicked); + Button *plusButton = createButton(tr("+"), &Calculator::additiveOperatorClicked); - Button *squareRootButton = createButton(tr("Sqrt"), SLOT(unaryOperatorClicked())); - Button *powerButton = createButton(tr("x\302\262"), SLOT(unaryOperatorClicked())); - Button *reciprocalButton = createButton(tr("1/x"), SLOT(unaryOperatorClicked())); - Button *equalButton = createButton(tr("="), SLOT(equalClicked())); + Button *squareRootButton = createButton(tr("Sqrt"), &Calculator::unaryOperatorClicked); + Button *powerButton = createButton(tr("x\302\262"), &Calculator::unaryOperatorClicked); + Button *reciprocalButton = createButton(tr("1/x"), &Calculator::unaryOperatorClicked); + Button *equalButton = createButton(tr("="), &Calculator::equalClicked); //! [4] //! [5] @@ -324,10 +324,11 @@ void Calculator::addToMemory() } //! [32] //! [34] -Button *Calculator::createButton(const QString &text, const char *member) +template +Button *Calculator::createButton(const QString &text, const PointerToMemberFunction &member) { Button *button = new Button(text); - connect(button, SIGNAL(clicked()), this, member); + connect(button, &Button::clicked, this, member); return button; } //! [34] diff --git a/examples/widgets/widgets/calculator/calculator.h b/examples/widgets/widgets/calculator/calculator.h index d4fa112909..42e9ac5335 100644 --- a/examples/widgets/widgets/calculator/calculator.h +++ b/examples/widgets/widgets/calculator/calculator.h @@ -39,7 +39,8 @@ private slots: //! [1] private: //! [1] //! [2] - Button *createButton(const QString &text, const char *member); + template + Button *createButton(const QString &text, const PointerToMemberFunction &member); void abortOperation(); bool calculate(double rightOperand, const QString &pendingOperator); //! [2] diff --git a/examples/widgets/widgets/tooltips/sortingbox.cpp b/examples/widgets/widgets/tooltips/sortingbox.cpp index 1f6de0bd8c..c77b3eaada 100644 --- a/examples/widgets/widgets/tooltips/sortingbox.cpp +++ b/examples/widgets/widgets/tooltips/sortingbox.cpp @@ -26,15 +26,15 @@ SortingBox::SortingBox(QWidget *parent) //! [3] newCircleButton = createToolButton(tr("New Circle"), QIcon(":/images/circle.png"), - SLOT(createNewCircle())); + &SortingBox::createNewCircle); newSquareButton = createToolButton(tr("New Square"), QIcon(":/images/square.png"), - SLOT(createNewSquare())); + &SortingBox::createNewSquare); newTriangleButton = createToolButton(tr("New Triangle"), QIcon(":/images/triangle.png"), - SLOT(createNewTriangle())); + &SortingBox::createNewTriangle); circlePath.addEllipse(QRect(0, 0, 100, 100)); squarePath.addRect(QRect(0, 0, 100, 100)); @@ -219,14 +219,15 @@ void SortingBox::createShapeItem(const QPainterPath &path, //! [21] //! [22] +template QToolButton *SortingBox::createToolButton(const QString &toolTip, - const QIcon &icon, const char *member) + const QIcon &icon, const PointerToMemberFunction &member) { QToolButton *button = new QToolButton(this); button->setToolTip(toolTip); button->setIcon(icon); button->setIconSize(QSize(32, 32)); - connect(button, SIGNAL(clicked()), this, member); + connect(button, &QToolButton::clicked, this, member); return button; } diff --git a/examples/widgets/widgets/tooltips/sortingbox.h b/examples/widgets/widgets/tooltips/sortingbox.h index 4fa9b4d36c..243f2e6caa 100644 --- a/examples/widgets/widgets/tooltips/sortingbox.h +++ b/examples/widgets/widgets/tooltips/sortingbox.h @@ -47,9 +47,10 @@ private: QPoint randomItemPosition(); QColor initialItemColor(); QColor randomItemColor(); + template QToolButton *createToolButton(const QString &toolTip, const QIcon &icon, //! [1] - const char *member); + const PointerToMemberFunction &member); //! [2] QList shapeItems;