SetFileTime on an image, File::open set filesize to 0
Solved
General and Desktop
-
Hello, i have a problem using QFile::setFileTime, when i try to open a ".jpg" file, the file's size is automatically set to 0. However, i have to open the file to setFileTime...
bool copyFileKeepingMetadatas(const QString& origin, const QString& destination) { QFileInfo fileInfo(origin); QDateTime birthTime = fileInfo.fileTime(QFile::FileBirthTime); QDateTime modifTime = fileInfo.fileTime(QFile::FileModificationTime); QDateTime accessTime = fileInfo.fileTime(QFile::FileAccessTime); if (QFile::exists((destination))) { QFile::remove(destination); } bool worked = QFile::copy(origin, destination); if (worked) { // Destination is an .jpg file QFile d(destination); if(d.open(QFile::WriteOnly)) { // Set file size to 0 event if i comment setFileTime below // setFileTime return false if file is not opened //d.setFileTime(accessTime, QFile::FileAccessTime); // d.setFileTime(modifTime, QFile::FileModificationTime); // d.setFileTime(birthTime, QFile::FileAccessTime); d.close(); return true; } else { return false; } } else { return false; } }
Is then an other way to modify image métadatas?
-
@ClementD said in SetFileTime on an image, File::open set filesize to 0:
when i try to open a ".jpg" file, the file's size is automatically set to 0.
What do you expect? See https://doc.qt.io/qt-5/qiodevice.html#OpenModeFlag-enum
-
Hello @Christian-Ehrlicher , I want to copy a file keeping file times from the original. When i open the file, i do not want to modify it's content (only date)
i also try to open it using QFile::WriteOnly | QFile::ExistingOnly flags or QFile::WriteOnly | QFile::Unbuffered, same issue