diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-07-21 01:04:40 +0300 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-09-08 19:17:36 +0300 |
commit | 09b852b1d8519db1b614a1a6438ff59a928f3b9f (patch) | |
tree | 4f1afedb79fbb7e9bbf3c2df491c41b3fbfec05e | |
parent | 9016def4dc75e35509cc1a5f5168514b0d88af56 (diff) |
examples/: compile with QT_NO_CONTEXTLESS_CONNECT
Examples are usually a good way to get to know a new codebase, do not
teach developers who are new to Qt about the 3-arg connect() to begin
with.
Drive-by changes:
- `this` can't be implicitly captured with [=] in a lambda, instead
capture by reference
- Update docs related to the sqlbrowser example; the overloaded signal
it mentions has been removed in Qt6
- In the sqlbrowser example, rename addConnection() (no-arg) overload to
openNewConnectionDialog, suggested in code review
Change-Id: I30c9f35bda4ac2f460d767ab7f84422ae3ed09f7
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r-- | examples/CMakeLists.txt | 2 | ||||
-rw-r--r-- | examples/corelib/bindableproperties/bindablesubscription/main.cpp | 12 | ||||
-rw-r--r-- | examples/corelib/bindableproperties/subscription/main.cpp | 8 | ||||
-rw-r--r-- | examples/sql/doc/src/drilldown.qdoc | 4 | ||||
-rw-r--r-- | examples/sql/drilldown/informationwindow.cpp | 8 | ||||
-rw-r--r-- | examples/sql/sqlbrowser/browser.cpp | 2 | ||||
-rw-r--r-- | examples/sql/sqlbrowser/browser.h | 2 | ||||
-rw-r--r-- | examples/sql/sqlbrowser/main.cpp | 15 | ||||
-rw-r--r-- | examples/vulkan/hellovulkancubes/renderer.cpp | 2 |
9 files changed, 24 insertions, 31 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 0f6e6ba425..e7ed9033f4 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,6 +3,8 @@ qt_examples_build_begin(EXTERNAL_BUILD) +add_compile_definitions(QT_NO_CONTEXTLESS_CONNECT) + add_subdirectory(corelib) add_subdirectory(embedded) if(TARGET Qt6::DBus) diff --git a/examples/corelib/bindableproperties/bindablesubscription/main.cpp b/examples/corelib/bindableproperties/bindablesubscription/main.cpp index dd4e26fb74..0eb8c1a76e 100644 --- a/examples/corelib/bindableproperties/bindablesubscription/main.cpp +++ b/examples/corelib/bindableproperties/bindablesubscription/main.cpp @@ -28,29 +28,29 @@ int main(int argc, char *argv[]) // Initialize subscription data QRadioButton *monthly = w.findChild<QRadioButton *>("btnMonthly"); - QObject::connect(monthly, &QRadioButton::clicked, [&] { + QObject::connect(monthly, &QRadioButton::clicked, monthly, [&] { subscription.setDuration(BindableSubscription::Monthly); }); QRadioButton *quarterly = w.findChild<QRadioButton *>("btnQuarterly"); - QObject::connect(quarterly, &QRadioButton::clicked, [&] { + QObject::connect(quarterly, &QRadioButton::clicked, quarterly, [&] { subscription.setDuration(BindableSubscription::Quarterly); }); QRadioButton *yearly = w.findChild<QRadioButton *>("btnYearly"); - QObject::connect(yearly, &QRadioButton::clicked, [&] { + QObject::connect(yearly, &QRadioButton::clicked, yearly, [&] { subscription.setDuration(BindableSubscription::Yearly); }); // Initialize user data QPushButton *germany = w.findChild<QPushButton *>("btnGermany"); - QObject::connect(germany, &QPushButton::clicked, [&] { + QObject::connect(germany, &QPushButton::clicked, germany, [&] { user.setCountry(BindableUser::Country::Germany); }); QPushButton *finland = w.findChild<QPushButton *>("btnFinland"); - QObject::connect(finland, &QPushButton::clicked, [&] { + QObject::connect(finland, &QPushButton::clicked, finland, [&] { user.setCountry(BindableUser::Country::Finland); }); QPushButton *norway = w.findChild<QPushButton *>("btnNorway"); - QObject::connect(norway, &QPushButton::clicked, [&] { + QObject::connect(norway, &QPushButton::clicked, norway, [&] { user.setCountry(BindableUser::Country::Norway); }); diff --git a/examples/corelib/bindableproperties/subscription/main.cpp b/examples/corelib/bindableproperties/subscription/main.cpp index 1f41486728..db2188b16c 100644 --- a/examples/corelib/bindableproperties/subscription/main.cpp +++ b/examples/corelib/bindableproperties/subscription/main.cpp @@ -64,25 +64,25 @@ int main(int argc, char *argv[]) // Track the price changes //! [connect-price-changed] - QObject::connect(&subscription, &Subscription::priceChanged, [&] { + QObject::connect(&subscription, &Subscription::priceChanged, priceDisplay, [&] { QLocale lc{QLocale::AnyLanguage, user.country()}; priceDisplay->setText(lc.toCurrencyString(subscription.price() / subscription.duration())); }); //! [connect-price-changed] //! [connect-validity-changed] - QObject::connect(&subscription, &Subscription::isValidChanged, [&] { + QObject::connect(&subscription, &Subscription::isValidChanged, priceDisplay, [&] { priceDisplay->setEnabled(subscription.isValid()); }); //! [connect-validity-changed] //! [connect-user] - QObject::connect(&user, &User::countryChanged, [&] { + QObject::connect(&user, &User::countryChanged, &subscription, [&] { subscription.calculatePrice(); subscription.updateValidity(); }); - QObject::connect(&user, &User::ageChanged, [&] { + QObject::connect(&user, &User::ageChanged, &subscription, [&] { subscription.updateValidity(); }); //! [connect-user] diff --git a/examples/sql/doc/src/drilldown.qdoc b/examples/sql/doc/src/drilldown.qdoc index 7d1c997aeb..3ef310db18 100644 --- a/examples/sql/doc/src/drilldown.qdoc +++ b/examples/sql/doc/src/drilldown.qdoc @@ -154,10 +154,6 @@ We need to use lambdas for connecting the \c enableButtons slot because its signature does not match \c QTextEdit::textChanged and \c QComboBox::currentIndexChanged. - Since the latter has another overload with the signature - \c {const QString &} and the selected signal would be ambiguous, - we need to use \c QOverload<int>::of to select a specific overload - for \c currentIndexChanged. We add all the widgets into a layout, store the item ID and the name of the displayed image file for future reference, and set diff --git a/examples/sql/drilldown/informationwindow.cpp b/examples/sql/drilldown/informationwindow.cpp index 4f9896d74d..614db9a9aa 100644 --- a/examples/sql/drilldown/informationwindow.cpp +++ b/examples/sql/drilldown/informationwindow.cpp @@ -37,12 +37,8 @@ InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *items, //! [3] //! [4] - connect(descriptionEditor, &QTextEdit::textChanged, [=]() { - enableButtons(); - }); - connect(imageFileEditor, &QComboBox::currentIndexChanged, [=]() { - enableButtons(); - }); + connect(descriptionEditor, &QTextEdit::textChanged, this, [this]() { enableButtons(); }); + connect(imageFileEditor, &QComboBox::currentIndexChanged, this, [this]() { enableButtons(); }); QFormLayout *formLayout = new QFormLayout; formLayout->addRow(itemLabel, itemText); diff --git a/examples/sql/sqlbrowser/browser.cpp b/examples/sql/sqlbrowser/browser.cpp index 98270fd5b5..077e8df51c 100644 --- a/examples/sql/sqlbrowser/browser.cpp +++ b/examples/sql/sqlbrowser/browser.cpp @@ -71,7 +71,7 @@ QSqlError Browser::addConnection(const QString &driver, const QString &dbName, c return err; } -void Browser::addConnection() +void Browser::openNewConnectionDialog() { QSqlConnectionDialog dialog(this); if (dialog.exec() != QDialog::Accepted) diff --git a/examples/sql/sqlbrowser/browser.h b/examples/sql/sqlbrowser/browser.h index cf959703b3..82702b2ae3 100644 --- a/examples/sql/sqlbrowser/browser.h +++ b/examples/sql/sqlbrowser/browser.h @@ -32,7 +32,7 @@ public slots: void exec(); void showTable(const QString &table); void showMetaData(const QString &table); - void addConnection(); + void openNewConnectionDialog(); void currentChanged() { updateActions(); } void about(); diff --git a/examples/sql/sqlbrowser/main.cpp b/examples/sql/sqlbrowser/main.cpp index c6babea96f..445c04637e 100644 --- a/examples/sql/sqlbrowser/main.cpp +++ b/examples/sql/sqlbrowser/main.cpp @@ -33,18 +33,17 @@ int main(int argc, char *argv[]) mainWin.setCentralWidget(&browser); QMenu *fileMenu = mainWin.menuBar()->addMenu(QObject::tr("&File")); - fileMenu->addAction(QObject::tr("Add &Connection..."), - [&]() { browser.addConnection(); }); + fileMenu->addAction(QObject::tr("Add &Connection..."), &browser, + &Browser::openNewConnectionDialog); fileMenu->addSeparator(); - fileMenu->addAction(QObject::tr("&Quit"), []() { qApp->quit(); }); + fileMenu->addAction(QObject::tr("&Quit"), qApp, &QApplication::quit); QMenu *helpMenu = mainWin.menuBar()->addMenu(QObject::tr("&Help")); - helpMenu->addAction(QObject::tr("About"), [&]() { browser.about(); }); - helpMenu->addAction(QObject::tr("About Qt"), []() { qApp->aboutQt(); }); + helpMenu->addAction(QObject::tr("About"), &browser, &Browser::about); + helpMenu->addAction(QObject::tr("About Qt"), qApp, &QApplication::aboutQt); - QObject::connect(&browser, &Browser::statusMessage, [&mainWin](const QString &text) { - mainWin.statusBar()->showMessage(text); - }); + QObject::connect(&browser, &Browser::statusMessage, &mainWin, + [&mainWin](const QString &text) { mainWin.statusBar()->showMessage(text); }); addConnectionsFromCommandline(app.arguments(), &browser); mainWin.show(); diff --git a/examples/vulkan/hellovulkancubes/renderer.cpp b/examples/vulkan/hellovulkancubes/renderer.cpp index 34023eefdb..037d97014c 100644 --- a/examples/vulkan/hellovulkancubes/renderer.cpp +++ b/examples/vulkan/hellovulkancubes/renderer.cpp @@ -38,7 +38,7 @@ Renderer::Renderer(VulkanWindow *w, int initialCount) m_blockMesh.load(QStringLiteral(":/block.buf")); m_logoMesh.load(QStringLiteral(":/qt_logo.buf")); - QObject::connect(&m_frameWatcher, &QFutureWatcherBase::finished, [this] { + QObject::connect(&m_frameWatcher, &QFutureWatcherBase::finished, m_window, [this] { if (m_framePending) { m_framePending = false; m_window->frameReady(); |