WriteLog.cpp 400 B

12345678910111213141516171819202122
  1. #include "WriteLog.h"
  2. void WriteLog::SaveLog(QString msg)
  3. {
  4. QString sFilePath = "test.txt";
  5. QFile file(sFilePath);
  6. if (file.size() > 1024 * 1024 * 10)
  7. {
  8. file.remove();
  9. file.deleteLater();
  10. return;
  11. }
  12. //·½Ê½£ºAppendΪ׷¼Ó£¬WriteOnly£¬ReadOnly
  13. if (!file.open(QIODevice::Append | QIODevice::Text)) {
  14. return;
  15. }
  16. QTextStream out(&file);
  17. out << msg << endl;
  18. out.flush();
  19. file.close();
  20. }