1指定文件的文件夹路径是否存在 QFile好像不会自动创建文件夹
2.可以利用C语言创建文件的方式
3.这段代码是我写的日志记录 仅供参考
QMutex mutex;
bool QZkFile::WriteLog(QString sText)
{
QString strPath = QZkFile::GetExePath();
QDateTime date = QDateTime::currentDateTime();
QString sDate = date.toString("yyyyMMdd");
QString strLogFile = strPath + "Log/Log" + sDate + ".txt";
QString sPreHeader = date.toString("yyyy-MM-dd hh:mm:ss ");
QString sLogPath = strPath + "Log/";
QDir dir;
dir.setPath(sLogPath);
if(!dir.exists())
dir.mkdir(sLogPath);
mutex.lock();
QFile file;
file.setFileName(strLogFile);
if (!file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Append))
return false;
QTextStream out(&file);
out <<sPreHeader<<sText<<"\n";
file.close();
mutex.unlock();
}