diff options
Diffstat (limited to 'examples/widgets/tutorials')
14 files changed, 134 insertions, 78 deletions
diff --git a/examples/widgets/tutorials/addressbook/part2/addressbook.cpp b/examples/widgets/tutorials/addressbook/part2/addressbook.cpp index 34fa5d2060..d5ee394abd 100644 --- a/examples/widgets/tutorials/addressbook/part2/addressbook.cpp +++ b/examples/widgets/tutorials/addressbook/part2/addressbook.cpp @@ -74,9 +74,12 @@ AddressBook::AddressBook(QWidget *parent) cancelButton->hide(); //! [pushbutton declaration] //! [connecting signals and slots] - connect(addButton, SIGNAL(clicked()), this, SLOT(addContact())); - connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact())); - connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); + connect(addButton, &QPushButton::clicked, + this, &AddressBook::addContact); + connect(submitButton, &QPushButton::clicked, + this, &AddressBook::submitContact); + connect(cancelButton, &QPushButton::clicked, + this, &AddressBook::cancel); //! [connecting signals and slots] //! [vertical layout] QVBoxLayout *buttonLayout1 = new QVBoxLayout; diff --git a/examples/widgets/tutorials/addressbook/part3/addressbook.cpp b/examples/widgets/tutorials/addressbook/part3/addressbook.cpp index caef83970a..b6d48f7a0d 100644 --- a/examples/widgets/tutorials/addressbook/part3/addressbook.cpp +++ b/examples/widgets/tutorials/addressbook/part3/addressbook.cpp @@ -74,13 +74,17 @@ AddressBook::AddressBook(QWidget *parent) previousButton = new QPushButton(tr("&Previous")); previousButton->setEnabled(false); //! [navigation pushbuttons] - - connect(addButton, SIGNAL(clicked()), this, SLOT(addContact())); - connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact())); - connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); + connect(addButton, &QPushButton::clicked, + this, &AddressBook::addContact); + connect(submitButton, &QPushButton::clicked, + this, &AddressBook::submitContact); + connect(cancelButton, &QPushButton::clicked, + this, &AddressBook::cancel); //! [connecting navigation signals] - connect(nextButton, SIGNAL(clicked()), this, SLOT(next())); - connect(previousButton, SIGNAL(clicked()), this, SLOT(previous())); + connect(nextButton, &QPushButton::clicked, + this, &AddressBook::next); + connect(previousButton, &QPushButton::clicked, + this, &AddressBook::previous); //! [connecting navigation signals] QVBoxLayout *buttonLayout1 = new QVBoxLayout; diff --git a/examples/widgets/tutorials/addressbook/part4/addressbook.cpp b/examples/widgets/tutorials/addressbook/part4/addressbook.cpp index 92f0776727..77ce216c07 100644 --- a/examples/widgets/tutorials/addressbook/part4/addressbook.cpp +++ b/examples/widgets/tutorials/addressbook/part4/addressbook.cpp @@ -79,15 +79,22 @@ AddressBook::AddressBook(QWidget *parent) previousButton = new QPushButton(tr("&Previous")); previousButton->setEnabled(false); - connect(addButton, SIGNAL(clicked()), this, SLOT(addContact())); - connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact())); + connect(addButton, &QPushButton::clicked, + this, &AddressBook::addContact); + connect(submitButton, &QPushButton::clicked, + this, &AddressBook::submitContact); //! [connecting edit and remove] - connect(editButton, SIGNAL(clicked()), this, SLOT(editContact())); - connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact())); + connect(editButton, &QPushButton::clicked, + this, &AddressBook::editContact); + connect(removeButton, &QPushButton::clicked, + this, &AddressBook::removeContact); //! [connecting edit and remove] - connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); - connect(nextButton, SIGNAL(clicked()), this, SLOT(next())); - connect(previousButton, SIGNAL(clicked()), this, SLOT(previous())); + connect(cancelButton, &QPushButton::clicked, + this, &AddressBook::cancel); + connect(nextButton, &QPushButton::clicked, + this, &AddressBook::next); + connect(previousButton, &QPushButton::clicked, + this, &AddressBook::previous); QVBoxLayout *buttonLayout1 = new QVBoxLayout; buttonLayout1->addWidget(addButton); diff --git a/examples/widgets/tutorials/addressbook/part5/addressbook.cpp b/examples/widgets/tutorials/addressbook/part5/addressbook.cpp index 6e09ec287d..5505a0e35c 100644 --- a/examples/widgets/tutorials/addressbook/part5/addressbook.cpp +++ b/examples/widgets/tutorials/addressbook/part5/addressbook.cpp @@ -86,16 +86,24 @@ AddressBook::AddressBook(QWidget *parent) dialog = new FindDialog(this); //! [instantiating FindDialog] - connect(addButton, SIGNAL(clicked()), this, SLOT(addContact())); - connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact())); - connect(editButton, SIGNAL(clicked()), this, SLOT(editContact())); - connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); - connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact())); + connect(addButton, &QPushButton::clicked, + this, &AddressBook::addContact); + connect(submitButton, &QPushButton::clicked, + this, &AddressBook::submitContact); + connect(editButton, &QPushButton::clicked, + this, &AddressBook::editContact); + connect(removeButton, &QPushButton::clicked, + this, &AddressBook::removeContact); + connect(cancelButton, &QPushButton::clicked, + this, &AddressBook::cancel); //! [signals and slots for find] - connect(findButton, SIGNAL(clicked()), this, SLOT(findContact())); + connect(findButton, &QPushButton::clicked, + this, &AddressBook::findContact); //! [signals and slots for find] - connect(nextButton, SIGNAL(clicked()), this, SLOT(next())); - connect(previousButton, SIGNAL(clicked()), this, SLOT(previous())); + connect(nextButton, &QPushButton::clicked, + this, &AddressBook::next); + connect(previousButton, &QPushButton::clicked, + this, &AddressBook::previous); QVBoxLayout *buttonLayout1 = new QVBoxLayout; buttonLayout1->addWidget(addButton); diff --git a/examples/widgets/tutorials/addressbook/part5/finddialog.cpp b/examples/widgets/tutorials/addressbook/part5/finddialog.cpp index b0d9a5e6e3..615b39d42f 100644 --- a/examples/widgets/tutorials/addressbook/part5/finddialog.cpp +++ b/examples/widgets/tutorials/addressbook/part5/finddialog.cpp @@ -68,8 +68,10 @@ FindDialog::FindDialog(QWidget *parent) setLayout(layout); setWindowTitle(tr("Find a Contact")); - connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked())); - connect(findButton, SIGNAL(clicked()), this, SLOT(accept())); + connect(findButton, &QPushButton::clicked, + this, &FindDialog::findClicked); + connect(findButton, &QPushButton::clicked, + this, &FindDialog::accept); } //! [constructor] //! [findClicked() function] diff --git a/examples/widgets/tutorials/addressbook/part6/addressbook.cpp b/examples/widgets/tutorials/addressbook/part6/addressbook.cpp index b2e361a45e..8e740cfffc 100644 --- a/examples/widgets/tutorials/addressbook/part6/addressbook.cpp +++ b/examples/widgets/tutorials/addressbook/part6/addressbook.cpp @@ -92,16 +92,26 @@ AddressBook::AddressBook(QWidget *parent) dialog = new FindDialog(this); - connect(addButton, SIGNAL(clicked()), this, SLOT(addContact())); - connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact())); - connect(editButton, SIGNAL(clicked()), this, SLOT(editContact())); - connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); - connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact())); - connect(findButton, SIGNAL(clicked()), this, SLOT(findContact())); - connect(nextButton, SIGNAL(clicked()), this, SLOT(next())); - connect(previousButton, SIGNAL(clicked()), this, SLOT(previous())); - connect(loadButton, SIGNAL(clicked()), this, SLOT(loadFromFile())); - connect(saveButton, SIGNAL(clicked()), this, SLOT(saveToFile())); + connect(addButton, &QPushButton::clicked, + this, &AddressBook::addContact); + connect(submitButton, &QPushButton::clicked, + this, &AddressBook::submitContact); + connect(editButton, &QPushButton::clicked, + this, &AddressBook::editContact); + connect(removeButton, &QPushButton::clicked, + this, &AddressBook::removeContact); + connect(cancelButton, &QPushButton::clicked, + this, &AddressBook::cancel); + connect(findButton, &QPushButton::clicked, + this, &AddressBook::findContact); + connect(nextButton, &QPushButton::clicked, + this, &AddressBook::next); + connect(previousButton, &QPushButton::clicked, + this, &AddressBook::previous); + connect(loadButton, &QPushButton::clicked, + this, &AddressBook::loadFromFile); + connect(saveButton, &QPushButton::clicked, + this, &AddressBook::saveToFile); QVBoxLayout *buttonLayout1 = new QVBoxLayout; buttonLayout1->addWidget(addButton); diff --git a/examples/widgets/tutorials/addressbook/part6/finddialog.cpp b/examples/widgets/tutorials/addressbook/part6/finddialog.cpp index 6a1e6b116f..c25cccd552 100644 --- a/examples/widgets/tutorials/addressbook/part6/finddialog.cpp +++ b/examples/widgets/tutorials/addressbook/part6/finddialog.cpp @@ -67,8 +67,10 @@ FindDialog::FindDialog(QWidget *parent) setLayout(layout); setWindowTitle(tr("Find a Contact")); - connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked())); - connect(findButton, SIGNAL(clicked()), this, SLOT(accept())); + connect(findButton, &QPushButton::clicked, + this, &FindDialog::findClicked); + connect(findButton, &QPushButton::clicked, + this, &FindDialog::accept); } void FindDialog::findClicked() diff --git a/examples/widgets/tutorials/addressbook/part7/addressbook.cpp b/examples/widgets/tutorials/addressbook/part7/addressbook.cpp index e946c873e3..717d0882af 100644 --- a/examples/widgets/tutorials/addressbook/part7/addressbook.cpp +++ b/examples/widgets/tutorials/addressbook/part7/addressbook.cpp @@ -92,17 +92,28 @@ AddressBook::AddressBook(QWidget *parent) dialog = new FindDialog(this); - connect(addButton, SIGNAL(clicked()), this, SLOT(addContact())); - connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact())); - connect(editButton, SIGNAL(clicked()), this, SLOT(editContact())); - connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); - connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact())); - connect(findButton, SIGNAL(clicked()), this, SLOT(findContact())); - connect(nextButton, SIGNAL(clicked()), this, SLOT(next())); - connect(previousButton, SIGNAL(clicked()), this, SLOT(previous())); - connect(loadButton, SIGNAL(clicked()), this, SLOT(loadFromFile())); - connect(saveButton, SIGNAL(clicked()), this, SLOT(saveToFile())); - connect(exportButton, SIGNAL(clicked()), this, SLOT(exportAsVCard())); + connect(addButton, &QPushButton::clicked, + this, &AddressBook::addContact); + connect(submitButton, &QPushButton::clicked, + this, &AddressBook::submitContact); + connect(editButton, &QPushButton::clicked, + this, &AddressBook::editContact); + connect(removeButton, &QPushButton::clicked, + this, &AddressBook::removeContact); + connect(cancelButton, &QPushButton::clicked, + this, &AddressBook::cancel); + connect(findButton, &QPushButton::clicked, + this, &AddressBook::findContact); + connect(nextButton, &QPushButton::clicked, + this, &AddressBook::next); + connect(previousButton, &QPushButton::clicked, + this, &AddressBook::previous); + connect(loadButton, &QPushButton::clicked, + this, &AddressBook::loadFromFile); + connect(saveButton, &QPushButton::clicked, + this, &AddressBook::saveToFile); + connect(exportButton, &QPushButton::clicked, + this, &AddressBook::exportAsVCard); QVBoxLayout *buttonLayout1 = new QVBoxLayout; buttonLayout1->addWidget(addButton); diff --git a/examples/widgets/tutorials/addressbook/part7/finddialog.cpp b/examples/widgets/tutorials/addressbook/part7/finddialog.cpp index 6a1e6b116f..c25cccd552 100644 --- a/examples/widgets/tutorials/addressbook/part7/finddialog.cpp +++ b/examples/widgets/tutorials/addressbook/part7/finddialog.cpp @@ -67,8 +67,10 @@ FindDialog::FindDialog(QWidget *parent) setLayout(layout); setWindowTitle(tr("Find a Contact")); - connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked())); - connect(findButton, SIGNAL(clicked()), this, SLOT(accept())); + connect(findButton, &QPushButton::clicked, + this, &FindDialog::findClicked); + connect(findButton, &QPushButton::clicked, + this, &FindDialog::accept); } void FindDialog::findClicked() diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp index 90f5f1a6b3..8bf83859a0 100644 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp +++ b/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp @@ -57,7 +57,8 @@ int main(int argc, char *argv[]) QTextEdit *textEdit = new QTextEdit; QPushButton *quitButton = new QPushButton("&Quit"); - QObject::connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit())); + QObject::connect(quitButton, &QPushButton::clicked, + qApp, &QApplication::quit); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(textEdit); diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp index 0a60c1cf16..d4b43eb034 100644 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp +++ b/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp @@ -71,7 +71,8 @@ Notepad::Notepad() textEdit = new QTextEdit; quitButton = new QPushButton(tr("Quit")); - connect(quitButton, SIGNAL(clicked()), this, SLOT(quit())); + connect(quitButton, &QPushButton::clicked, + this, &Notepad::quit); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(textEdit); diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp index 6d9e96a3d4..8c5fbc70ca 100644 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp +++ b/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp @@ -73,14 +73,16 @@ private: Notepad::Notepad() { - loadAction = new QAction(tr("&Load"), this); saveAction = new QAction(tr("&Save"), this); exitAction = new QAction(tr("E&xit"), this); - connect(loadAction, SIGNAL(triggered()), this, SLOT(load())); - connect(saveAction, SIGNAL(triggered()), this, SLOT(save())); - connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(loadAction, &QAction::triggered, + this, &Notepad::load); + connect(saveAction, &QAction::triggered, + this, &Notepad::save); + connect(exitAction, &QAction::triggered, + qApp, &QApplication::quit); fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(loadAction); diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp index b2b4a73874..cc3e1a261c 100644 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp +++ b/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp @@ -73,14 +73,16 @@ private: Notepad::Notepad() { - openAction = new QAction(tr("&Load"), this); saveAction = new QAction(tr("&Save"), this); exitAction = new QAction(tr("E&xit"), this); - connect(openAction, SIGNAL(triggered()), this, SLOT(open())); - connect(saveAction, SIGNAL(triggered()), this, SLOT(save())); - connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(openAction, &QAction::triggered, + this, &Notepad::open); + connect(saveAction, &QAction::triggered, + this, &Notepad::save); + connect(exitAction, &QAction::triggered, + qApp, &QApplication::quit); fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(openAction); diff --git a/examples/widgets/tutorials/widgets/nestedlayouts/main.cpp b/examples/widgets/tutorials/widgets/nestedlayouts/main.cpp index 9acc74b469..8880dbe3d0 100644 --- a/examples/widgets/tutorials/widgets/nestedlayouts/main.cpp +++ b/examples/widgets/tutorials/widgets/nestedlayouts/main.cpp @@ -76,25 +76,26 @@ int main(int argc, char *argv[]) //! [set up the model] QStandardItemModel model; - model.setHorizontalHeaderLabels( - QStringList() << QApplication::translate("nestedlayouts", "Name") - << QApplication::translate("nestedlayouts", "Office")); + model.setHorizontalHeaderLabels({ QApplication::translate("nestedlayouts", "Name"), + QApplication::translate("nestedlayouts", "Office") }); - QList<QStringList> rows = QList<QStringList>() - << (QStringList() << "Verne Nilsen" << "123") - << (QStringList() << "Carlos Tang" << "77") - << (QStringList() << "Bronwyn Hawcroft" << "119") - << (QStringList() << "Alessandro Hanssen" << "32") - << (QStringList() << "Andrew John Bakken" << "54") - << (QStringList() << "Vanessa Weatherley" << "85") - << (QStringList() << "Rebecca Dickens" << "17") - << (QStringList() << "David Bradley" << "42") - << (QStringList() << "Knut Walters" << "25") - << (QStringList() << "Andrea Jones" << "34"); + const QStringList rows[] = { + QStringList{ QStringLiteral("Verne Nilsen"), QStringLiteral("123") }, + QStringList{ QStringLiteral("Carlos Tang"), QStringLiteral("77") }, + QStringList{ QStringLiteral("Bronwyn Hawcroft"), QStringLiteral("119") }, + QStringList{ QStringLiteral("Alessandro Hanssen"), QStringLiteral("32") }, + QStringList{ QStringLiteral("Andrew John Bakken"), QStringLiteral("54") }, + QStringList{ QStringLiteral("Vanessa Weatherley"), QStringLiteral("85") }, + QStringList{ QStringLiteral("Rebecca Dickens"), QStringLiteral("17") }, + QStringList{ QStringLiteral("David Bradley"), QStringLiteral("42") }, + QStringList{ QStringLiteral("Knut Walters"), QStringLiteral("25") }, + QStringList{ QStringLiteral("Andrea Jones"), QStringLiteral("34") } + }; - foreach (QStringList row, rows) { - QList<QStandardItem *> items; - foreach (QString text, row) + QList<QStandardItem *> items; + for (const QStringList &row : rows) { + items.clear(); + for (const QString &text : row) items.append(new QStandardItem(text)); model.appendRow(items); } |