Solved QDateTime to QString conversion
-
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
-
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"); -
buid month ""
it is a build path ""qdebug display this one sir not display the date and time
-
@Rameshguru Can you check fileInfo.exists() ?
-
@Rameshguru said in QDATETIME TO QString conversion:
("hh:ss:mm");
Also note you have seconds before minutes. Is this what you wanted?
-
@Ratzz i want last compile time of build file
-
@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? -
@Ratzz"
error
QFileinfo no member name exist -
@Rameshguru said in QDATETIME TO QString conversion:
QFileinfo no member name exist
Can you show your code?
-
@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");
-
@Ratzz said in QDATETIME TO QString conversion:
QFileinfo no member name exist
It's called exists() not exist()...
-
@Rameshguru This is you problem. Please verify your file path. Try adding one more '' in your path. e.g. D:\\WorkingCode...
-
@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"