From c2751b1d664748cfbd05d2e397f95f2cc0bec13f Mon Sep 17 00:00:00 2001 From: Andre de la Rocha Date: Mon, 21 Aug 2017 13:23:48 +0200 Subject: Active Qt Examples: Brush up to C++ 11 Use nullptr, member initialization, new connect syntax, QStringLiteral, etc. Change-Id: Ia79473ca302216f91eec6a32f670cf606761ed0d Reviewed-by: Michael Winkelmann Reviewed-by: Friedemann Kleint --- examples/activeqt/simpleqml/main.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'examples/activeqt/simpleqml/main.cpp') diff --git a/examples/activeqt/simpleqml/main.cpp b/examples/activeqt/simpleqml/main.cpp index 8983b22..bd7dd33 100644 --- a/examples/activeqt/simpleqml/main.cpp +++ b/examples/activeqt/simpleqml/main.cpp @@ -50,19 +50,15 @@ class Controller : public QObject Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged) Q_PROPERTY(QColor color READ color NOTIFY valueChanged) public: - explicit Controller(QWidget *parent = 0) : - QObject(parent), - m_value(0) + explicit Controller(QWidget *parent = nullptr) : + QObject(parent) { } qreal value() const { return m_value; } void setValue(qreal value) { - if (value < 0) value = 0; - if (value > 1) value = 1; - - m_value = value; + m_value = qBound(qreal(0.0), value, qreal(1.0)); valueChanged(); } @@ -84,7 +80,7 @@ signals: void valueChanged(); private: - qreal m_value; + qreal m_value = 0; }; class QSimpleQmlAx : public QMainWindow @@ -94,7 +90,7 @@ class QSimpleQmlAx : public QMainWindow Q_CLASSINFO("InterfaceID", "{A5EC7D99-CEC9-4BD1-8336-ED15A579B185}") Q_CLASSINFO("EventsID", "{5BBFBCFD-20FD-48A3-96C7-1F6649CD1F52}") public: - explicit QSimpleQmlAx(QWidget *parent = 0) : + explicit QSimpleQmlAx(QWidget *parent = nullptr) : QMainWindow(parent) { auto ui = new QQuickWidget(this); @@ -103,10 +99,10 @@ public: qmlRegisterType("app", 1, 0, "Controller"); // Initialize view - ui->rootContext()->setContextProperty("context", QVariant::fromValue(new Controller(this))); + ui->rootContext()->setContextProperty(QStringLiteral("context"), QVariant::fromValue(new Controller(this))); ui->setMinimumSize(200, 200); ui->setResizeMode(QQuickWidget::SizeRootObjectToView); - ui->setSource(QUrl("qrc:/main.qml")); + ui->setSource(QUrl(QStringLiteral("qrc:/main.qml"))); setCentralWidget(ui); } }; -- cgit v1.2.1