定义结构体
typedef struct People
{
QString name;
int age;
QString address;
QString telpNum;
People()
{
name = "张三";
age = 20;
address = "北京市海淀区";
telpNum = "123456789";
}
}t_People;
使用结构体
#include "structwidget.h"
#include "ui_structwidget.h"
#include <QDebug>
structWidget::structWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::structWidget)
{
ui->setupUi(this);
struct People p1;
qDebug()<<p1.name<<" "<<p1.age<<" "<<p1.address<<" "<<p1.telpNum;
//(打印结果 初始值)"张三" 20 "北京市海淀区" "123456789"
struct People p2;
p2.name = "李四";
p2.age = 30;
p2.address = "北京市朝阳区";
p2.telpNum = "987654321";
qDebug()<<p2.name<<" "<<p2.age<<" "<<p2.address<<" "<<p2.telpNum;
//(赋值后打印)"李四" 30 "北京市朝阳区" "987654321"
t_People p3;
qDebug()<<p3.name<<" "<<p3.age<<" "<<p3.address<<" "<<p3.telpNum;
}