제거하는 동안 내 응용 프로그램에서 만든 모든 임시 파일을 삭제하려고합니다. 다음 코드를 사용합니다 :Windows에서 Qt를 사용하여 현재로드 된 파일 삭제
bool DeleteFileNow(QString filenameStr)
{
wchar_t* filename;
filenameStr.toWCharArray(filename);
QFileInfo info(filenameStr);
// don't do anything if the file doesn't exist!
if (!info.exists())
return false;
// determine the path in which to store the temp filename
wchar_t* path;
info.absolutePath().toWCharArray(path);
TRACE("Generating temporary name");
// generate a guaranteed to be unique temporary filename to house the pending delete
wchar_t tempname[MAX_PATH];
if (!GetTempFileNameW(path, L".xX", 0, tempname))
return false;
TRACE("Moving real file name to dummy");
// move the real file to the dummy filename
if (!MoveFileExW(filename, tempname, MOVEFILE_REPLACE_EXISTING))
{
// clean up the temp file
DeleteFileW(tempname);
return false;
}
TRACE("Queueing the OS");
// queue the deletion (the OS will delete it when all handles (ours or other processes) close)
return DeleteFileW(tempname) != FALSE;
}
내 응용 프로그램이 충돌합니다. 나는 그 작업을 수행하기위한 몇 가지 누락 된 Windows dll로 인해 생각합니다. Qt 만 사용하여 동일한 작업을 수행하는 다른 방법이 있습니까?
toWCharArray의 문서에 따르면 "배열 (파일의 파일 이름)은 호출자가 할당해야하며 전체 문자열을 저장할 충분한 공간이 있어야합니다". –
@Roku 감사합니다. – ssk