指定文件路徑,然後打開文件。
QFile *file = new QFile(QDir::currentPath()+"/"+"user1");//此路徑下沒有就會自己創建一個
while(!file->open(QIODevice::ReadWrite | QIODevice::Append));//以讀寫切追加寫入的方式操作文本
需要寫入的數據
QTextStream txtOutput(file);
QString n1("小明 :");
QString t("小華 :");
txtOutput << n1<< endl;
txtOutput << t<< endl;
file->close();
效果如下