Qt写入txt文件

来源:互联网 发布:美国2016年gdp数据 编辑:程序博客网 时间:2024/04/30 05:50
void MainWindow::on_pushButton_clicked()
{
    QDateTime da_time;
    QString time_str=da_time.currentDateTime().toString("yyyy-MM-dd HH-mm-ss");
    QString runPath = QCoreApplication::applicationFilePath();
    ui->label->setText(runPath);
    QDir *TEST = new QDir;
    bool exist = TEST->exists("TEST");
    if(!exist)
          bool ok = TEST->mkdir("TEST");
   QString fileName = "TEST/1.txt";
   QString str="0000000nnnnnnnnnnnnnnnn";
   QFile file(fileName);
   if(!file.open(QIODevice::WriteOnly  | QIODevice::Text|QIODevice::Append))
   {
      QMessageBox::warning(this,"sdf","can't open",QMessageBox::Yes);
   }
   QTextStream in(&file);
   in<<time_str+":"+str<<"\n";
   file.close();
}

0 0