#include <QObject>//класс со свойством nameclass CMyClass : public QObject{Q_OBJECTQ_PROPERTY(QString name READ getName WRITE setName)public: CMyClass(QObject *pobj=NULL):\ QObject(pobj){} const QString & getName()const{return m_strName;} void setName(const QString & strName){m_strName = strName;}private: QString m_strName;};//...//main#include <QtGui/QApplication>#include "mainwindow.h"#include "../cmyclass.h"int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; w.show(); CMyClass MyObj; MyObj.setProperty("name","Alex_cs_gsp"); return a.exec();}
C++ (Qt)MyObj.setProperty("name","Alex_cs_gsp");
C++ (Qt)MyObj.setProperty("name", QVariant("Alex_cs_gsp"));
C++ (Qt)#ifndef CMYCLASS_H#define CMYCLASS_H #include <QObject>#include <QString> class CMyClass : public QObject{Q_OBJECT Q_PROPERTY(QString name READ getName WRITE setName) public: CMyClass(QObject *pobj=0): QObject(pobj){} const QString & getName()const{return m_strName;} void setName(const QString & strName){m_strName = strName;} private: QString m_strName;}; #endif // CMYCLASS_H
C++ (Qt)#include <QtCore/QCoreApplication>#include "cmyclass.h"#include <QVariant> int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); CMyClass MyObj; MyObj.setProperty("name", QVariant("Alex_cs_gsp")); return a.exec();}
C++ (Qt)MyObj.setProperty("name", "Alex_cs_gsp");