class MyClass : public QObject{ public: MyClass( QObject * parent ) : QObject( parent ) { ... } private: ...}
MyClass * mc = new MyClass( someWidget );
MyClass * mc = someWidget->findChild < MyClass * > ();
class MyProperties : public QObject{ Q_OBJECT Q_PROPERTY( int digit READ digit ) Q_PROPERTY( QString errorString READ errorString )public: MyProperties( QObject * parent ); int digit() const; QString errorString() const;};...QWidget * widget = get_widget_from_form();QObject * properties = new MyProperties( widget );properties->setObjectName( "my_properties" );...
QObject * properties = get_widget_from_form()->findChild<QObject*>( "my_properties" );if ( properties ){ int digit = propertiers->property( "digit" ).toInt(); QString error = properties->property( "errorString" ).toString();}
class MyProperties : public QObject { Q_OBJECT Q_PROPERTY( int digit READ digit WRITE setDigit ) Q_PROPERTY( QString errorString READ errorString WRITE setErrorString ) public: MyProperties( QObject * parent ) : QObject( parent ), digit_( 0 ) { } int digit() const { return digit_; } void setDigit( int digit ) { digit_ = digit; } QString errorString() const { return error_string_; } void setErrorString( const QString & error ) { error_string_ = error; }private: int digit_; QString error_string_;};...QObject * properties = get_widget_from_form()->findChild<QObject*>( "my_properties" ); if ( properties ) { int digit = properties->property( "digit" ).toInt(); QString error = properties->property( "errorString" ).toString(); properties->setProperty( "digit", 123 ); properties->setProperty( "errorString", "kernel panic" );}