当前位置: 首页 > news >正文

张北网站建设公司今日新闻头条大事

张北网站建设公司,今日新闻头条大事,网站开发的项目,台州公司做网站文章目录 界面学生类序列化函数反序列化函数刷新所选择的下拉表值添加 界面 学生类 // 创建学生信息类 class studentInfo { public:QString id; // 学号QString name; // 学生姓名QString age; // 学生年龄// 重写QDataStream& operator<<操作符&…

文章目录

  • 界面
  • 学生类
  • 序列化函数
  • 反序列化函数
  • 刷新所选择的下拉表值
  • 添加

在这里插入图片描述

界面

在这里插入图片描述

学生类

// 创建学生信息类
class studentInfo
{
public:QString id;     // 学号QString name;   // 学生姓名QString age;        // 学生年龄// 重写QDataStream& operator<<操作符,做数据序列化操作friend QDataStream& operator<<(QDataStream &stream, const studentInfo &student){// 将数据输入流对象中stream << student.id;stream << student.name;stream << student.age;return stream;}// 重写QDataStream& operator>>操作符,做数据反序列化操作friend QDataStream& operator>>(QDataStream &stream, studentInfo &student){// 从流对象中输出数据到学生结构体引用中stream >> student.id;stream >> student.name;stream >> student.age;return stream;}
};

序列化函数

将其放入容器内方便便利每一个学生参数的值

 QList<studentInfo> list;studentInfo student;

获取文本编辑的值读取到序列化文件中进行保存

//保存
void MainWindow::on_pushButton_clicked()
{studentInfo student;//序列化为二进制文件存在本地QFile file(QApplication::applicationDirPath()+"/"+"student.st");           //定义文件路径file.open(QIODevice::WriteOnly); //以只写模式打开QDataStream out(&file);          //定义数据流student.id=ui->m_Id->text();student.age=ui->m_Age->text();student.name=ui->m_Name->text();list.append(student);out<<list;qDebug()<<list[0].id;file.close();qDebug()<<(QString("OK"));ReShowCombox();
}

刷新下拉表的值

void MainWindow::ReShowCombox()
{// 获取 studentInfo 对象if(list.size()>0){ui->comboBox->addItem(list.last().name);}
}

反序列化函数

读取文件的值,添加到下拉列表中

void MainWindow::GetFile()
{studentInfo student;//反序列化本地二进制文件到程序中QFile file(QApplication::applicationDirPath()+"/"+"student.st");//文件在程序运行目录下if(file.exists())//如果文件存在,则从文件读取数据{file.open(QIODevice::ReadOnly);QDataStream in(&file);in>>list;file.close();}// 获取 studentInfo 对象if(list.size()>0){student.id=list.at(0).id;student.age=list.at(0).age;student.name=list.at(0).name;ui->m_Id->setText(student.id);ui->m_Age->setText(student.age);ui->m_Name->setText(student.name);for(int i=0;i<list.size();i++){ui->comboBox->addItem(list.at(i).name);}}}

刷新所选择的下拉表值

连接信号与槽函数

 connect(ui->comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::on_comboBox_currentIndexChanged);

获取到当前的值

void MainWindow::on_comboBox_currentIndexChanged(int index)
{if (index >= 0) {// 获取当前选中项的 studentInfo 对象studentInfo student = list.at(index);// 刷新其他控件的值ui->m_Id->setText(student.id);ui->m_Name->setText(student.name);ui->m_Age->setText(student.age);}
}

添加

void MainWindow::on_pushButton_2_clicked()
{ui->m_Id->setText("");ui->m_Name->setText("");ui->m_Age->setText("");}
http://www.dt0577.cn/news/35120.html

相关文章:

  • 杭州滨江网站建设中国关键词
  • 系统学做网站外链代发2分一条
  • 做模板网站赚钱吗西安seo工作室
  • 网站建设用户量分析济南头条新闻热点
  • vue快速搭建网站免费seo网站的工具
  • 域名做好了怎么做网站内容seo入门基础知识
  • 网站开发外包方案怎么做百度推广平台
  • 石家庄市网站制作seo网站内容优化有哪些
  • 网站建设 生产play商店
  • 如何建网站卖东西搜狐视频
  • 自己能不能做个网站东莞seo优化团队
  • google网站陕西seo优化
  • 什么网站可以做邮件列表windows优化大师有用吗
  • 手机搜索网站建设宜昌网站seo
  • 做服装团购有哪些网站有哪些输入搜索内容
  • 怎么快速建网站360收录提交
  • 如何用rp做网站步骤最有效的100个营销方法
  • 重庆智慧团建网站登录平台全网关键词搜索
  • 大兴做网站建设制作宁波网络营销推广咨询报价
  • 长沙百度快速排名优化seo 网站排名
  • 郑州网站托管公司哪家好交易链接大全
  • 有做微推客的网站吗百度识图网页版在线使用
  • 淘宝网站建设可靠关键词查询工具包括哪些
  • 医院网站建设滞后广告公司职位
  • python做网站和php百度seo快速提升排名
  • 那个网站可以做双色球号码对比的怎么买域名自己做网站
  • 权威的公司网站制作网站整合营销推广
  • 建网站用什么系统软文自助发稿平台oem
  • 宿州商务网站建设网红推广接单平台
  • 有什么设计网站国际热点新闻