QDateTime da_time; QString time_str=da_time.currentDateTime().toString("yyyy-MM-dd HH:mm:ss zzz "); 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.html"; QString str="0000000nnnnnnnnnnnnnnnn"; QFile file(fileName); //若非记录需清楚历史的情况,只使用WriteOnly即可 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<<"<br>"; file.close();
转载于:https://my.oschina.net/qtplus/blog/816046