Revamp Bindable Subscription ex: Cretae 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.6 6.5
Change-Id: I92eed0a371bf6383ddb1e938646029f1c24242bf
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
Rym Bouabid 2023-09-21 13:05:41 +02:00
parent a69be76a30
commit ed72a5d9e1

View File

@ -14,6 +14,8 @@
#include <QSpinBox>
#include <QString>
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<QRadioButton *>("btnMonthly");
QRadioButton *monthly = w.findChild<QRadioButton *>(u"btnMonthly"_s);
QObject::connect(monthly, &QRadioButton::clicked, monthly, [&] {
subscription.setDuration(BindableSubscription::Monthly);
});
QRadioButton *quarterly = w.findChild<QRadioButton *>("btnQuarterly");
QRadioButton *quarterly = w.findChild<QRadioButton *>(u"btnQuarterly"_s);
QObject::connect(quarterly, &QRadioButton::clicked, quarterly, [&] {
subscription.setDuration(BindableSubscription::Quarterly);
});
QRadioButton *yearly = w.findChild<QRadioButton *>("btnYearly");
QRadioButton *yearly = w.findChild<QRadioButton *>(u"btnYearly"_s);
QObject::connect(yearly, &QRadioButton::clicked, yearly, [&] {
subscription.setDuration(BindableSubscription::Yearly);
});
// Initialize user data
QPushButton *germany = w.findChild<QPushButton *>("btnGermany");
QPushButton *germany = w.findChild<QPushButton *>(u"btnGermany"_s);
QObject::connect(germany, &QPushButton::clicked, germany, [&] {
user.setCountry(BindableUser::Country::Germany);
});
QPushButton *finland = w.findChild<QPushButton *>("btnFinland");
QPushButton *finland = w.findChild<QPushButton *>(u"btnFinland"_s);
QObject::connect(finland, &QPushButton::clicked, finland, [&] {
user.setCountry(BindableUser::Country::Finland);
});
QPushButton *norway = w.findChild<QPushButton *>("btnNorway");
QPushButton *norway = w.findChild<QPushButton *>(u"btnNorway"_s);
QObject::connect(norway, &QPushButton::clicked, norway, [&] {
user.setCountry(BindableUser::Country::Norway);
});
QSpinBox *ageSpinBox = w.findChild<QSpinBox *>("ageSpinBox");
QSpinBox *ageSpinBox = w.findChild<QSpinBox *>(u"ageSpinBox"_s);
QBindable<int> ageBindable(ageSpinBox, "value");
user.bindableAge().setBinding([ageBindable](){ return ageBindable.value();});
QLabel *priceDisplay = w.findChild<QLabel *>("priceDisplay");
QLabel *priceDisplay = w.findChild<QLabel *>(u"priceDisplay"_s);
// Track price changes
//! [update-ui]