Advertisement
Guest User

Untitled

a guest
Jan 18th, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. class Settings : public QObject
  2. {
  3.     Q_OBJECT
  4.     Q_PROPERTY(bool value READ getValue WRITE setValue NOTIFY valueChanged)
  5. public:
  6.     explicit Settings(QObject *parent = 0);
  7.     bool getValue() {return this->value;}
  8.     void setValue(bool val) {this->value = val; emit valueChanged(val);}
  9. private:
  10.     bool value;
  11. signals:
  12.     void valueChanged(bool);
  13. };
  14.  
  15.  
  16. // In main method:
  17. Settings* settings = new Settings();
  18. view->rootContext()->setContextProperty("settings", settings);
  19.  
  20. // In QML:
  21. Switch {
  22.     checked: settings.value
  23.     //if using the following it is working but warning about a binding loop:
  24.     //onCheckedChanged: settings.value = checked
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement