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 add time stamp at the end of the file name?
QtWS25 Last Chance

How to add time stamp at the end of the file name?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 1.7k 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.
  • F Offline
    F Offline
    firsnur96
    wrote on last edited by
    #1

    I want to save files according to time, because of it i want to time stamp

    QFile file("Infos/info.tm" );
    

    How can i add time stamp at the end of the above file?

    jsulmJ JonBJ 2 Replies Last reply
    0
    • F firsnur96

      I want to save files according to time, because of it i want to time stamp

      QFile file("Infos/info.tm" );
      

      How can i add time stamp at the end of the above file?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @firsnur96 said in How to add time stamp at the end of the file name?:

      How can i add time stamp at the end of the above file?

      Using https://doc.qt.io/qt-5/qstring.html#arg and https://doc.qt.io/qt-5/qtime.html#toString

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      5
      • F firsnur96

        I want to save files according to time, because of it i want to time stamp

        QFile file("Infos/info.tm" );
        

        How can i add time stamp at the end of the above file?

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #3

        @firsnur96
        Change the string to add whatever format you want from whatever time (current time) you want?
        Though I actually suggest not adding it right at the end as that will destroy the .tm file type suffix, so better: Infos/info_some_timestamp.tm.

        F 1 Reply Last reply
        0
        • JonBJ JonB

          @firsnur96
          Change the string to add whatever format you want from whatever time (current time) you want?
          Though I actually suggest not adding it right at the end as that will destroy the .tm file type suffix, so better: Infos/info_some_timestamp.tm.

          F Offline
          F Offline
          firsnur96
          wrote on last edited by
          #4

          @JonB
          I did it like that but it didnt work. I get this error message

          QString::arg: Argument missing: Sakla/info, 11052021-113822
          QIODevice::write (QFile, "Sakla/info"): device not open

          QDateTime now = QDateTime::currentDateTime();
           QString timestamp = now.toString(QLatin1String("ddMMyyyy-hhmmss"));
           QString filename=QString::fromLatin1("Sakla/info").arg(timestamp);
           QFile file(filename);
          
          J.HilkJ 1 Reply Last reply
          0
          • F firsnur96

            @JonB
            I did it like that but it didnt work. I get this error message

            QString::arg: Argument missing: Sakla/info, 11052021-113822
            QIODevice::write (QFile, "Sakla/info"): device not open

            QDateTime now = QDateTime::currentDateTime();
             QString timestamp = now.toString(QLatin1String("ddMMyyyy-hhmmss"));
             QString filename=QString::fromLatin1("Sakla/info").arg(timestamp);
             QFile file(filename);
            
            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @firsnur96 said in How to add time stamp at the end of the file name?:

            QString filename=QString::fromLatin1("Sakla/info%1.tm").arg(timestamp);


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            F 1 Reply Last reply
            4
            • J.HilkJ J.Hilk

              @firsnur96 said in How to add time stamp at the end of the file name?:

              QString filename=QString::fromLatin1("Sakla/info%1.tm").arg(timestamp);

              F Offline
              F Offline
              firsnur96
              wrote on last edited by
              #6

              @J-Hilk thank you

              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