Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Settings : public QObject
- {
- Q_OBJECT
- Q_PROPERTY(bool value READ getValue WRITE setValue NOTIFY valueChanged)
- public:
- explicit Settings(QObject *parent = 0);
- bool getValue() {return this->value;}
- void setValue(bool val) {this->value = val; emit valueChanged(val);}
- private:
- bool value;
- signals:
- void valueChanged(bool);
- };
- // In main method:
- Settings* settings = new Settings();
- view->rootContext()->setContextProperty("settings", settings);
- // In QML:
- Switch {
- checked: settings.value
- //if using the following it is working but warning about a binding loop:
- //onCheckedChanged: settings.value = checked
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement