QFile::copy() doesn't keep "last modified time"?



  • Hi,

    Just consulting that does anyone knows
    how to keep a file's "last modified time"
    after QFile::copy copy it to somewhere?

    On windows, that seems no problem,
    copied files can keep it's original "last modified time",

    But on Linux(ubuntu 14.04),
    the "last modified time" would be updated to the time when it was copied.

    I thought the "copy" should keep all info of file including "last modified time", but seems it doesn't on Linux(ubuntu14.04)?

    So I would like to consult that does anyone knows the problem of copy and "last modified time" on Linux(ubuntu 14.04)?

    Thanks~

    • list item


  • It is not a problem. You have created a new file with the same content as the original. It was last accessed and modified shortly after it was created, and the time stamps reflect that.

    You can use the POSIX standard utime() function to set the modification and access times on a file. You can get these time stamps for the original file from a QFileInfo object or using the POSIX utimes() function (may be easier).



  • Hi @ChrisW67 ,

    ...You can use the POSIX standard utime() function to set the modification and access times on a file...

    Thank you, that works~


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.