1、
int LogFile(QString &_str) { QDateTime datetime = QDateTime::currentDateTime();//获取系统现在的时间 QString strTime = datetime.toString("hh:mm:ss.zzz"); //设置显示格式 #ifdef BUILD_EXE QString strExeDll = "[EXE]"; #else QString strExeDll = "[DLL]"; #endif _str = strTime+" : "+ strExeDll +" "+_str+ " "; // ZC: 本exe所在路径 QString strPath; QDir dir; strPath = dir.currentPath(); QString strDate = datetime.toString("yyyyMMdd"); //设置显示格式 // ZC: log文件的 路径 及 文件名 QString strLogFileName = strPath+"/"+strDate+".log"; HANDLE hLogFile = CreateFileA(strLogFileName.toLatin1(), GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_ALWAYS/*CREATE_NEW*/, 0, 0); if (hLogFile == INVALID_HANDLE_VALUE) return GetLastError(); //BOOL B = SetEndOfFile(hLogFile); if ( INVALID_SET_FILE_POINTER == SetFilePointer(hLogFile, 0, 0, FILE_END) ) { int iErr = GetLastError(); CloseHandle(hLogFile); return iErr; } DWORD dwWritten = 0; BOOL B = WriteFile(hLogFile, _str.toLatin1(), _str.length(), &dwWritten, NULL); if (! B) { int iErr = GetLastError(); CloseHandle(hLogFile); return iErr; } CloseHandle(hLogFile); return 0; }
2、
3、