Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    3
    1685
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ChunKai-Wang
      ChunKai-Wang last edited by ChunKai-Wang

      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
      1 Reply Last reply Reply Quote 0
      • C
        ChrisW67 last edited by

        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).

        ChunKai-Wang 1 Reply Last reply Reply Quote 0
        • ChunKai-Wang
          ChunKai-Wang @ChrisW67 last edited by

          Hi @ChrisW67 ,

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

          Thank you, that works~

          1 Reply Last reply Reply Quote 0
          • First post
            Last post