您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

55 行
1.2 KiB

  1. #include "communicationhistory.h"
  2. bool SaveDate(QWidget *parent, QTextEdit *edit)
  3. {
  4. QString fileName = QFileDialog::getSaveFileName(
  5. parent,
  6. "保存文本",
  7. QDir::homePath() + "/note.txt",
  8. "文本文件 (*.txt);;所有文件 (*)");
  9. if (fileName.isEmpty())
  10. return false;
  11. QFile file(fileName);
  12. if (!file.open(QIODevice::Append | QIODevice::Text))
  13. {
  14. QMessageBox::warning(parent, "错误", "无法打开文件");
  15. return false;
  16. }
  17. if (file.size() > 0)
  18. file.write("\n");
  19. QTextStream out(&file);
  20. out.setCodec("UTF-8");
  21. out << edit->toPlainText();
  22. file.close();
  23. return true;
  24. }
  25. bool ReadDate(QWidget *parent, QTextEdit *edit)
  26. {
  27. QString fileName = QFileDialog::getOpenFileName(
  28. parent,
  29. "打开文本",
  30. QDir::homePath(),
  31. "文本文件 (*.txt);;所有文件 (*)");
  32. if (fileName.isEmpty())
  33. return false;
  34. QFile file(fileName);
  35. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
  36. {
  37. QMessageBox::warning(parent, "错误", "无法读取文件");
  38. return false;
  39. }
  40. QTextStream in(&file);
  41. in.setCodec("UTF-8");
  42. edit->setPlainText(in.readAll());
  43. file.close();
  44. return true;
  45. }