Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Text
Posted by: Dean Sinaean
Added: Jul 7, 2021 7:03 AM
Views: 32
Tags: no tags
  1.     QFile file("test.txt");
  2.     if (file.exists()) {
  3.         qDebug() << " file exsits, content:";
  4.         file.open(QIODevice::ReadWrite);
  5.         QByteArray fileContent = file.readAll();
  6.         qDebug() << fileContent.toStdString().c_str();
  7.         qDebug() << "removing...";
  8.         file.close();
  9.         file.remove();
  10.         qDebug() << "done.";
  11.     }
  12.     if (!file.open(QIODevice::OpenModeFlag::ReadWrite)) {
  13.         qDebug() << "open file failed";
  14.     }
  15.     file.write("hello1");
  16.     file.seek(0);
  17.     qDebug() << "file new content " << file.readAll().toStdString().c_str();