C++ (Qt)class QSignalBlocker{public: inline explicit QSignalBlocker(QObject *o); inline explicit QSignalBlocker(QObject &o); inline ~QSignalBlocker(); #ifdef Q_COMPILER_RVALUE_REFS inline QSignalBlocker(QSignalBlocker &&other); inline QSignalBlocker &operator=(QSignalBlocker &&other);#endif inline void reblock(); inline void unblock();private: Q_DISABLE_COPY(QSignalBlocker) QObject * m_o; bool m_blocked; bool m_inhibited;};
C++ (Qt)#include <iostream>#include <functional> template <class T, class Obj>class property{public: typedef std::function<T(Obj*)> getter_t; typedef std::function<void(Obj*, const T&)> setter_t; void init(Obj* obj, getter_t get, setter_t set) { object = obj; getter = get; setter = set; } property& operator=(const T& val) { setter(object, val); return *this; } operator T() const { return getter(object); } private: Obj* object; getter_t getter; setter_t setter;}; class test{public: test() { intProperty.init(this, &test::get, &test::set); } property<int, test> intProperty; private: int value; int get() const { std::cout << "test::get() const" << std::endl; return value; } void set(int val) { std::cout << "test::set(int)" << std::endl; value = val; }}; int main(){ test t; t.intProperty = 123; // здесь будет вызван метод void test::set(int) int a = t.intProperty; // здесь будет вызван метод int test::get() const return 0;}
C++ (Qt)t.intProperty++;