Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get a date and time of file creation

How to get a date and time of file creation

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 10.1k Views
  • 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.
  • V Offline
    V Offline
    VladimirPivovar
    wrote on last edited by
    #1

    I created a list of files:
    static QStringList files;
    declared variable, which will put the date in a different format
    static QString fileCreatedAt = NULL;

    in one branch of CASE prescribed the following code:

    static QFileInfo InfoAboutCurrentFile (files.at (i));
    fileCreatedAt = InfoAboutCurrentFile.created (). ToString ();

    an error of type QDateTime.

    invalid use of incomplete type Struct QDateTime

    Tell me how you can get creation date of files in a loop in the thread and even CASE (correctly declare the constructor for information on the following file?) format datetime and unixtimestamp?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      You most probably forgot to include the corresponding header, <code>#include <QtCore/QDateTime></code>.

      In addition, it is <code>.toString()</code>, not <code>.ToString()</code>. Is there any particular reason all your variables are <code>static</code>?

      1 Reply Last reply
      0
      • ZlatomirZ Offline
        ZlatomirZ Offline
        Zlatomir
        wrote on last edited by
        #3

        Since "created()":http://doc.qt.nokia.com/4.7-snapshot/qfileinfo.html#created returns a QDateTime you need the definition of that class, so have you tried #include <QDateTime>?

        https://forum.qt.io/category/41/romanian

        1 Reply Last reply
        0
        • V Offline
          V Offline
          VladimirPivovar
          wrote on last edited by
          #4

          connected headers and working! The next time I'll be careful with connecting headers. I thought the creation date and that was: I got the date the file was created on my disk. But originally it was created in a different place and date of creation it is different. Can tell me how to read the original creation date of a file?

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            Qt passes the information it retrieves from the operating system and the file system. You will have to make sure that the timestamps are preserved when the files are copied to your disk - otherwise the information is lost.

            1 Reply Last reply
            0
            • JeroentjehomeJ Offline
              JeroentjehomeJ Offline
              Jeroentjehome
              wrote on last edited by
              #6

              Well, maybe when you have files like a picture that includes information inside it you are able to get the production date, type of camera model etc. The QFileInfo just gives back the information of the file itself, so when copied the original date may be lost.
              Greetz

              Greetz, Jeroen

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved