Nelle finestre include qt_windows.h
e gioca con la data di modifica e di creazione.
QDateTime newModifiedTime=ui->dateTimeEdit_modified->dateTime();
QDateTime newCreationDate=TimeEdit_Creation->dateTime();
FILETIME pmodifiedtime,pcreationtime;
HANDLE hfile;
LPCWSTR filename=Filename.toStdWString().c_str();
hfile=CreateFile(filename,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(hfile==INVALID_HANDLE_VALUE)
{
QMessageBox::information(this,"Failed","Unable to open file,check file permission");
}
else
{
LONGLONG ll = Int32x32To64(newCreationDate.toTime_t(), 10000000) + 116444736000000000;
pcreationtime.dwLowDateTime = (DWORD) ll;
pcreationtime.dwHighDateTime = ll >> 32;
LONGLONG ll2 = Int32x32To64(newModifiedTime.toTime_t(), 10000000) + 116444736000000000;
pmodifiedtime.dwLowDateTime = (DWORD) ll2;
pmodifiedtime.dwHighDateTime = ll2 >> 32;
if(!SetFileTime(hfile,&pcreationtime,NULL,&pmodifiedtime))
{
QMessageBox::information(this,"Failed","Unable to set Date And Time");
}
else
{
QMessageBox::information(this,"Success","Date And Time Updated");
ui->lineEdit_FileName->clear();
}
}
CloseHandle(hfile);
For linux add includono utime.h
e fcntl.h
poi
struct utimbuf timebuffer;
timebuffer.modtime=newModifiedTime.toTime_t();
const char *filename=Filename.toAscii();
if((utime(filename,&timebuffer))<0)
{
QMessageBox::information(this,"Error","Unable to set Time");
}
else
{
QMessageBox::information(this,"Success","Date Changed");
}
fonte
2015-09-29 16:11:26
Hai trovato una soluzione? Ho lo stesso problema. È possibile utilizzare Qt ?. Grazie –