Örnek
Şöyle
yaparız
// Sy_test.h - The wrapped class
class Sy_test : public QObject
{
Q_OBJECT
Q_PROPERTY( bool prop READ getProp WRITE setProp NOTIFY propChanged )
public:
Sy_test( QObject* parent = nullptr ) :
QObject{ parent },
prop_{ false } {}
bool getProp() const { return prop_; }
public slots:
void setProp( bool value )
{
if ( value != prop_) {
prop_ = value;
emit propChanged( prop_);
}
}
signals:
void propChanged (bool value);
private:
bool prop_;
};
Örnek
Şöyle
yaparız.
class Widget : public QObject {
Q_OBJECT
Q_PROPERTY(int size READ size WRITE setSize NOTIFY sizeChanged)
public:
Widget(QObject * parent = nullptr) : QObject(parent){}
int size() const;
public slots:
void setSize(int new_size);
signals:
void sizeChanged(int); //!< signals a size change
private:
int m_size = 0; //!< the Widget's size, see #size.
};
Şöyle
yaparız.
void Widget::setSize(int new_size) {
if(new_size != m_size) {
m_size = new_size;
emit sizeChanged(m_size);
}
}
int Widget::size() const {
return m_size;
}