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>
This commit is contained in:
parent
9016def4dc
commit
09b852b1d8
@ -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)
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user