diff options
Diffstat (limited to 'examples/corelib/bindableproperties/subscription/main.cpp')
-rw-r--r-- | examples/corelib/bindableproperties/subscription/main.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/examples/corelib/bindableproperties/subscription/main.cpp b/examples/corelib/bindableproperties/subscription/main.cpp index 8b3f37ab7c..3f98da7467 100644 --- a/examples/corelib/bindableproperties/subscription/main.cpp +++ b/examples/corelib/bindableproperties/subscription/main.cpp @@ -6,11 +6,14 @@ #include "user.h" #include <QApplication> -#include <QButtonGroup> #include <QLabel> +#include <QLocale> #include <QPushButton> #include <QRadioButton> #include <QSpinBox> +#include <QString> + +using namespace Qt::StringLiterals; int main(int argc, char *argv[]) { @@ -24,64 +27,65 @@ int main(int argc, char *argv[]) SubscriptionWindow w; // Initialize subscription data - QRadioButton *monthly = w.findChild<QRadioButton *>("btnMonthly"); + QRadioButton *monthly = w.findChild<QRadioButton *>(u"btnMonthly"_s); QObject::connect(monthly, &QRadioButton::clicked, &subscription, [&] { subscription.setDuration(Subscription::Monthly); }); - QRadioButton *quarterly = w.findChild<QRadioButton *>("btnQuarterly"); + QRadioButton *quarterly = w.findChild<QRadioButton *>(u"btnQuarterly"_s); QObject::connect(quarterly, &QRadioButton::clicked, &subscription, [&] { subscription.setDuration(Subscription::Quarterly); }); - QRadioButton *yearly = w.findChild<QRadioButton *>("btnYearly"); + QRadioButton *yearly = w.findChild<QRadioButton *>(u"btnYearly"_s); QObject::connect(yearly, &QRadioButton::clicked, &subscription, [&] { subscription.setDuration(Subscription::Yearly); }); // Initialize user data - QPushButton *germany = w.findChild<QPushButton *>("btnGermany"); + QPushButton *germany = w.findChild<QPushButton *>(u"btnGermany"_s); QObject::connect(germany, &QPushButton::clicked, &user, [&] { - user.setCountry(User::Germany); + user.setCountry(User::Country::Germany); }); - QPushButton *finland = w.findChild<QPushButton *>("btnFinland"); + QPushButton *finland = w.findChild<QPushButton *>(u"btnFinland"_s); QObject::connect(finland, &QPushButton::clicked, &user, [&] { - user.setCountry(User::Finland); + user.setCountry(User::Country::Finland); }); - QPushButton *norway = w.findChild<QPushButton *>("btnNorway"); + QPushButton *norway = w.findChild<QPushButton *>(u"btnNorway"_s); QObject::connect(norway, &QPushButton::clicked, &user, [&] { - user.setCountry(User::Norway); + user.setCountry(User::Country::Norway); }); - QSpinBox *ageSpinBox = w.findChild<QSpinBox *>("ageSpinBox"); + QSpinBox *ageSpinBox = w.findChild<QSpinBox *>(u"ageSpinBox"_s); QObject::connect(ageSpinBox, &QSpinBox::valueChanged, &user, [&](int value) { user.setAge(value); }); // Initialize price data - QLabel *priceDisplay = w.findChild<QLabel *>("priceDisplay"); + QLabel *priceDisplay = w.findChild<QLabel *>(u"priceDisplay"_s); priceDisplay->setText(QString::number(subscription.price())); priceDisplay->setEnabled(subscription.isValid()); // Track the price changes //! [connect-price-changed] - QObject::connect(&subscription, &Subscription::priceChanged, [&] { - priceDisplay->setText(QString::number(subscription.price())); + 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] |