feat: Meat-Object System

MeatObjectSystem(元对象系统)、Propert(属性和动态属性)和Q_CLASSINFO()(附加信息宏)的介绍和使用
This commit is contained in:
touwoyimuli 2019-09-13 19:05:45 +08:00
parent 468e203866
commit 2c52f1d7e3

View File

@ -45,8 +45,8 @@ void ExWidget::onAgeChange(int val)
ExPerson* person = qobject_cast<ExPerson *>(sender()); //类型投射 ExPerson* person = qobject_cast<ExPerson *>(sender()); //类型投射
QString name = person->property("name").toString(); QString name = person->property("name").toString();
QString sex = person->property("sex").toString(); QString sex = person->property("sex").toString();
int age = person->getAge(); //通过接口函数,获得年龄 int age = person->getAge(); //通过接口函数,获得年龄
//或使用 int age = person->property("age").toInt(); //或使用 int age = person->property("age").toInt();
ui->textEdit->appendPlainText(name+","+sex + QString::asprintf(",年龄=%d",age)); ui->textEdit->appendPlainText(name+","+sex + QString::asprintf(",年龄=%d",age));
} }
@ -54,7 +54,7 @@ void ExWidget::onSpinValChange(int val)
{ {
Q_UNUSED(val) Q_UNUSED(val)
QSpinBox* spin = qobject_cast<QSpinBox *>(sender()); //类型投射 QSpinBox* spin = qobject_cast<QSpinBox *>(sender()); //类型投射
if (spin->property("isBoy").toBool()) if (spin->property("isBoy").toBool())
m_boy->setAge(ui->spinBoy->value()); m_boy->setAge(ui->spinBoy->value());
else else