//para1:应用名称
//para2:日志文件名
//para3:公司名称
static QString getLogDirForQt(const QString & appName,
const QString & logFileName,
const QString & strCompanyShortName = "Company")
{
QString fullLogPath = QDir::cleanPath(QDir::toNativeSeparators(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)));
QStringList dirNames;
dirNames = fullLogPath.split('/');
if(dirNames.count()<=0)
dirNames = fullLogPath.split('\\');
Q_ASSERT(dirNames.count() >0 );
if (!(QCoreApplication::applicationName().isNull() || QCoreApplication::applicationName().isEmpty()))
{
dirNames.removeLast();
}
if (!(QCoreApplication::organizationName().isNull() || QCoreApplication::organizationName().isEmpty()))
{
dirNames.removeLast();
}
fullLogPath = QDir::cleanPath(dirNames.join(QDir::separator()));
if (!fullLogPath.endsWith(QDir::separator()))
fullLogPath.append(QDir::separator());
fullLogPath.append(strCompanyShortName);
fullLogPath.append(QDir::separator());
fullLogPath.append(appName);
fullLogPath.append(QDir::separator());
fullLogPath.append("log");
fullLogPath.append(QDir::separator());
fullLogPath = QDir::toNativeSeparators(fullLogPath);
QDir dir(fullLogPath);
if (!dir.exists(fullLogPath))
dir.mkpath(fullLogPath);
fullLogPath.append(logFileName);
return fullLogPath;
}
}