文件操作
打开文件
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b5688354677a9b44d0fa20752ee7edef.png)
void Widget::on_open_clicked()
{
QString textdir=QFileDialog::getOpenFileName(this,"open file","C:/User/19583/Desktop/","*.txt");
QFile file(textdir);
if(!file.open(QIODevice::ReadOnly))return ;
QByteArray arr;
while(!file.atEnd())
{
arr+=file.readLine();
}
this->ui->textEdit->setText(arr);
file.close();
}
保存文件
void Widget::on_save_clicked()
{
QString filename=QFileDialog::getSaveFileName(this,"save file","C:/untitle.txt","*.docx,*.txt");
QFile file(filename);
if(!file.open(QIODevice::WriteOnly))return ;
QString text=ui->textEdit->toPlainText();
file.write(text.toUtf8());
file.close();
}