summaryrefslogtreecommitdiff
path: root/examples/activeqt/simpleqml/main.cpp
diff options
context:
space:
mode:
authorAndre de la Rocha <andre.rocha@qt.io>2017-08-21 13:23:48 +0200
committerAndre de la Rocha <andre.rocha@qt.io>2017-08-23 11:01:43 +0000
commitc2751b1d664748cfbd05d2e397f95f2cc0bec13f (patch)
tree6a7a884caf28250927ee66f395e0634470ac0851 /examples/activeqt/simpleqml/main.cpp
parentb3e88744f36144db7cda0b85c161cdb10026eb65 (diff)
downloadqtactiveqt-c2751b1d664748cfbd05d2e397f95f2cc0bec13f.tar.gz
Active Qt Examples: Brush up to C++ 11
Use nullptr, member initialization, new connect syntax, QStringLiteral, etc. Change-Id: Ia79473ca302216f91eec6a32f670cf606761ed0d Reviewed-by: Michael Winkelmann <michael.winkelmann@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'examples/activeqt/simpleqml/main.cpp')
-rw-r--r--examples/activeqt/simpleqml/main.cpp18
1 files changed, 7 insertions, 11 deletions
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<Controller>("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);
}
};