c++ - How to interact with the value of a Slider in Sailfish Silica / QML? -



c++ - How to interact with the value of a Slider in Sailfish Silica / QML? -

i seem totally lost in declaration of forms in qml. have c++ object set q_properties, have access object of class in qml, , want utilize sliders in qml. how create value of slider update info of properties in object, , vise-versa?

if it's regular qml, next approaches work.

context property

use explicit binding or utilize slider's valuechanged signal:

#include <qguiapplication> #include <qtqml> class object : public qobject { q_object q_property(qreal value read value write setvalue notify valuechanged) public: explicit object(qobject *parent = 0) : qobject(parent), mvalue(0) { } qreal value() const { homecoming mvalue; } void setvalue(qreal value) { if (value != mvalue) { mvalue = value; emit valuechanged(); } } signals: qreal valuechanged(); private: qreal mvalue; }; int main(int argc, char *argv[]) { qguiapplication app(argc, argv); object object; qqmlapplicationengine engine; engine.rootcontext()->setcontextproperty("object", &object); engine.load(qurl(qstringliteral("qrc:///main.qml"))); homecoming app.exec(); } #include "main.moc"

main.qml:

import qtquick 2.3 import qtquick.controls 1.2 applicationwindow { width: 400 height: 400 visible: true binding { target: object property: "value" value: slider.value } slider { id: slider // can react valuechanged signal of slider: //onvaluechanged: object.value = value } } registered qml type

use simple binding:

#include <qguiapplication> #include <qtqml> class object : public qobject { q_object q_property(qreal value read value write setvalue notify valuechanged) public: explicit object(qobject *parent = 0) : qobject(parent), mvalue(0) { } qreal value() const { homecoming mvalue; } void setvalue(qreal value) { if (value != mvalue) { mvalue = value; emit valuechanged(); } } signals: qreal valuechanged(); private: qreal mvalue; }; int main(int argc, char *argv[]) { qguiapplication app(argc, argv); qmlregistertype<object>("test", 1, 0, "object"); qqmlapplicationengine engine; engine.load(qurl(qstringliteral("qrc:///main.qml"))); homecoming app.exec(); } #include "main.moc"

main.qml:

import qtquick 2.3 import qtquick.controls 1.2 import test 1.0 applicationwindow { width: 400 height: 400 visible: true object { id: object value: slider.value onvaluechanged: print(value) } slider { id: slider } }

c++ qml sailfish-os

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -