码迷,mamicode.com
首页 > 其他好文 > 详细

Qfile

时间:2019-05-02 18:48:57      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:alt   student   拼接字符串   set   format   qstring   lse   add   read   

技术图片

技术图片

打开方式:

技术图片

 1 void AddStudents::write_to_file(QString src){
 2     QFile file("stu.txt");
 3     if (!file.open(QIODevice::Append | QIODevice::Text)){
 4         QMessageBox::critical(this,"打开文件错误","确认");
 5         return;
 6     }
 7     QTextStream out(&file);
 8     out << src;
 9 
10 }
 1     if(context.length() != 0 && name != "" && id !="" && ins.length()!= 0){
 2         int res = QMessageBox::information(this,"请确认信息",context,"确认","取消");
 3         if(res == 0){
 4             //点击确定
 5             //由于准备采用readline的方式来读取文件,所以不能是用‘\n‘来拼接字符串,换成‘ ‘符号来拼接
 6             QString src_s = name +  + id+ +sex+ +sche+ +age+ +ins;
 7             write_to_file(src_s);
 8             //恢复添加界面属性值为初始值
 9             clear_on_addstudent_ok();
10         }
11     }else{
12         QMessageBox::critical(this,"请确认信息","信息不完整,请重新输入!","确认","取消");
13         //重新设置光标位置。这里设置name对应的lineEdit控件获取光标
14         this->ui->lineedit_name->setFocus();
15     }

 

Qfile

标签:alt   student   拼接字符串   set   format   qstring   lse   add   read   

原文地址:https://www.cnblogs.com/data1213/p/10802822.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!