From 1b78e645e160c5350b8c77a36cf5cab4b8ac20c7 Mon Sep 17 00:00:00 2001 From: Rym Bouabid Date: Thu, 21 Sep 2023 13:05:41 +0200 Subject: [PATCH] Revamp Bindable Subscription ex: Create QString using a Literal operator Create QString at compile time using the literal operator""s instead of using pointer to characters. This way, no conversion or allocation will occur at runtime. Task-number: QTBUG-117422 Pick-to: 6.5 Change-Id: I92eed0a371bf6383ddb1e938646029f1c24242bf Reviewed-by: Ivan Solovev (cherry picked from commit ed72a5d9e11382f8c5a10924702beed809343809) --- .../bindablesubscription/main.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/corelib/bindableproperties/bindablesubscription/main.cpp b/examples/corelib/bindableproperties/bindablesubscription/main.cpp index 86c222a6ab3..519f3de4ef9 100644 --- a/examples/corelib/bindableproperties/bindablesubscription/main.cpp +++ b/examples/corelib/bindableproperties/bindablesubscription/main.cpp @@ -14,6 +14,8 @@ #include #include +using namespace Qt::StringLiterals; + int main(int argc, char *argv[]) { QApplication a(argc, argv); @@ -25,38 +27,38 @@ int main(int argc, char *argv[]) // when subscription is out of scope so is window // Initialize subscription data - QRadioButton *monthly = w.findChild("btnMonthly"); + QRadioButton *monthly = w.findChild(u"btnMonthly"_s); QObject::connect(monthly, &QRadioButton::clicked, [&] { subscription.setDuration(BindableSubscription::Monthly); }); - QRadioButton *quarterly = w.findChild("btnQuarterly"); + QRadioButton *quarterly = w.findChild(u"btnQuarterly"_s); QObject::connect(quarterly, &QRadioButton::clicked, [&] { subscription.setDuration(BindableSubscription::Quarterly); }); - QRadioButton *yearly = w.findChild("btnYearly"); + QRadioButton *yearly = w.findChild(u"btnYearly"_s); QObject::connect(yearly, &QRadioButton::clicked, [&] { subscription.setDuration(BindableSubscription::Yearly); }); // Initialize user data - QPushButton *germany = w.findChild("btnGermany"); + QPushButton *germany = w.findChild(u"btnGermany"_s); QObject::connect(germany, &QPushButton::clicked, [&] { user.setCountry(BindableUser::Country::Germany); }); - QPushButton *finland = w.findChild("btnFinland"); + QPushButton *finland = w.findChild(u"btnFinland"_s); QObject::connect(finland, &QPushButton::clicked, [&] { user.setCountry(BindableUser::Country::Finland); }); - QPushButton *norway = w.findChild("btnNorway"); + QPushButton *norway = w.findChild(u"btnNorway"_s); QObject::connect(norway, &QPushButton::clicked, [&] { user.setCountry(BindableUser::Country::Norway); }); - QSpinBox *ageSpinBox = w.findChild("ageSpinBox"); + QSpinBox *ageSpinBox = w.findChild(u"ageSpinBox"_s); QBindable ageBindable(ageSpinBox, "value"); user.bindableAge().setBinding([ageBindable](){ return ageBindable.value();}); - QLabel *priceDisplay = w.findChild("priceDisplay"); + QLabel *priceDisplay = w.findChild(u"priceDisplay"_s); // Track price changes //! [update-ui]