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. SetFileTime on an image, File::open set filesize to 0

SetFileTime on an image, File::open set filesize to 0

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 449 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.
  • C Offline
    C Offline
    ClementD
    wrote on 18 Jul 2020, 09:09 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 18 Jul 2020, 09:37 last edited by
      #2

      @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

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ClementD
        wrote on 18 Jul 2020, 09:42 last edited by ClementD
        #3

        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

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ClementD
          wrote on 18 Jul 2020, 09:46 last edited by
          #4

          Problem solved using if(d.open(QFile::WriteOnly | QFile::Append)) to open th file

          1 Reply Last reply
          0

          3/4

          18 Jul 2020, 09:42

          • Login

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