QDir *dir = new QDir;
QDateTime currentTime = QDateTime::currentDateTime();
QString logName = "log_" + currentTime.toString("yyyyMMddhhmmss");
bool exist = dir.exists(QDir::currentPath().append("/log"));
if(!exist)
{
dir.mkpath(QDir::currentPath().append("/log"));
dir.setPath(QDir::currentPath().append("/log"));
}
QFile *file = new QFile(logName + ".txt");
dir.setCurrent(QDir::currentPath().append("/log"));
while (!file.open(QIODevice::WriteOnly | QIODevice::append));
{
QTextStream txtOutput(file);
txtOutput << str << endl;
file.close();
}