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. QDateTime to QString conversion
Forum Updated to NodeBB v4.3 + New Features

QDateTime to QString conversion

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 5 Posters 14.9k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    Rameshguru
    wrote on last edited by aha_1980
    #1

    how to convert QDateTime to QString
    here i have attach my code
    QFileInfo fileInfo;
    fileInfo.setFile("D:\WorkingCode\build\Release\sample.exe");
    QDateTime buildtime = fileInfo.lastModified().currentDateTime();
    qDebug() << "buid month " << buildtime.toString("yyyy-MM-dd");
    qDebug() << "it is a build path " << buildtime.toString("hh:ss:mm");

    i dont want to current date time , i want build file creating time

    RatzzR 1 Reply Last reply
    0
    • Maaz MominM Offline
      Maaz MominM Offline
      Maaz Momin
      wrote on last edited by
      #2

      Just remove currentDateTime.

      QDateTime buildtime = fileInfo.lastModified();
      qDebug() << "buid month " << buildtime.toString("yyyy-MM-dd");
      qDebug() << "it is a build path " << buildtime.toString("hh:ss:mm");

      1 Reply Last reply
      3
      • R Offline
        R Offline
        Rameshguru
        wrote on last edited by
        #3

        @Maaz-Momin

        buid month ""
        it is a build path ""

        qdebug display this one sir not display the date and time

        1 Reply Last reply
        0
        • Maaz MominM Offline
          Maaz MominM Offline
          Maaz Momin
          wrote on last edited by Maaz Momin
          #4

          @Rameshguru Can you check fileInfo.exists() ?

          1 Reply Last reply
          3
          • R Rameshguru

            how to convert QDateTime to QString
            here i have attach my code
            QFileInfo fileInfo;
            fileInfo.setFile("D:\WorkingCode\build\Release\sample.exe");
            QDateTime buildtime = fileInfo.lastModified().currentDateTime();
            qDebug() << "buid month " << buildtime.toString("yyyy-MM-dd");
            qDebug() << "it is a build path " << buildtime.toString("hh:ss:mm");

            i dont want to current date time , i want build file creating time

            RatzzR Offline
            RatzzR Offline
            Ratzz
            wrote on last edited by
            #5

            @Rameshguru said in QDATETIME TO QString conversion:

            ("hh:ss:mm");

            Also note you have seconds before minutes. Is this what you wanted?

            --Alles ist gut.

            1 Reply Last reply
            1
            • R Offline
              R Offline
              Rameshguru
              wrote on last edited by
              #6

              @Ratzz i want last compile time of build file

              RatzzR 1 Reply Last reply
              0
              • R Rameshguru

                @Ratzz i want last compile time of build file

                RatzzR Offline
                RatzzR Offline
                Ratzz
                wrote on last edited by
                #7

                @Rameshguru
                This works for me https://forum.qt.io/topic/98741/qdatetime-to-qstring-conversion/2.
                Can you check fileInfo.exist() as @Maaz-Momin suggested?

                --Alles ist gut.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  Rameshguru
                  wrote on last edited by
                  #8

                  @Ratzz"
                  error
                  QFileinfo no member name exist

                  RatzzR Maaz MominM 2 Replies Last reply
                  0
                  • R Rameshguru

                    @Ratzz"
                    error
                    QFileinfo no member name exist

                    RatzzR Offline
                    RatzzR Offline
                    Ratzz
                    wrote on last edited by
                    #9

                    @Rameshguru said in QDATETIME TO QString conversion:

                    QFileinfo no member name exist

                    Can you show your code?

                    --Alles ist gut.

                    jsulmJ 1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      Rameshguru
                      wrote on last edited by
                      #10

                      @Ratzz
                      QFileInfo fileInfo;
                      fileInfo.setFile("D:\WorkingCode\build\Release\sample.exe");

                      	QDateTime buildtime = fileInfo.lastModified();
                      	
                      	qDebug() << "buid month " << buildtime.toString("yyyy-MM-dd");
                      	qDebug() << "it is a build path " << buildtime.toString("hh:mm:ss");
                      
                      JKSHJ 1 Reply Last reply
                      0
                      • RatzzR Ratzz

                        @Rameshguru said in QDATETIME TO QString conversion:

                        QFileinfo no member name exist

                        Can you show your code?

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

                        @Ratzz said in QDATETIME TO QString conversion:

                        QFileinfo no member name exist

                        It's called exists() not exist()...

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

                        1 Reply Last reply
                        3
                        • R Rameshguru

                          @Ratzz"
                          error
                          QFileinfo no member name exist

                          Maaz MominM Offline
                          Maaz MominM Offline
                          Maaz Momin
                          wrote on last edited by
                          #12

                          @Rameshguru This is you problem. Please verify your file path. Try adding one more '' in your path. e.g. D:\\WorkingCode...

                          1 Reply Last reply
                          0
                          • R Rameshguru

                            @Ratzz
                            QFileInfo fileInfo;
                            fileInfo.setFile("D:\WorkingCode\build\Release\sample.exe");

                            	QDateTime buildtime = fileInfo.lastModified();
                            	
                            	qDebug() << "buid month " << buildtime.toString("yyyy-MM-dd");
                            	qDebug() << "it is a build path " << buildtime.toString("hh:mm:ss");
                            
                            JKSHJ Offline
                            JKSHJ Offline
                            JKSH
                            Moderators
                            wrote on last edited by JKSH
                            #13

                            @Rameshguru said in QDateTime to QString conversion:

                              fileInfo.setFile("D:\WorkingCode\build\Release\sample.exe");
                            

                            \ is an escape character in C++ strings. Your path is invalid.

                            In Qt, you should use / instead: "D:/WorkingCode/build/Release/sample.exe"

                            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                            1 Reply Last reply
                            2

                            • Login

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