void SerialPortShell::SaveDate() { QFileDialog dlg(this); //获取内容的保存路径 QString fileName = dlg.getSaveFileName(this, tr("Save As"), "./", tr("Text File(*.txt)")); if( fileName == "" ) { return; } //内容保存到路径文件 QFile file(fileName); //以文本方式打开 if( file.open(QIODevice::WriteOnly | QIODevice::Text) ) { QTextStream out(&file); //IO设备对象的地址对其进行初始化 out << ui->plainTextEdit_recevieMessage->toPlainText() << endl; //输出 QMessageBox::warning(this, tr("Finish"), tr("Successfully save the file!")); file.close(); } else { QMessageBox::warning(this, tr("Error"), tr("File to open file!")); } }