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 write metadata to a file and read it again?

How to write metadata to a file and read it again?

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 7.2k 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.
  • D Offline
    D Offline
    dulajun
    wrote on 25 May 2013, 20:43 last edited by
    #1

    I want to develop application for monitoring the changes occurred on a folder and all its sub-folders which include moving, deleting, copying, deleting and adding (by saving or adding from a place out the main folder).
    And I want to use metadata to store information about the file (history and relation to the others).
    I see that there is a class called QMetaDataReaderControl is that what I need? if "yes" how to do that. Could any one give me a simple example.

    Thanks in advance.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on 25 May 2013, 22:36 last edited by
      #2

      For the first part, monitoring file/directory changes, a QFileSystemWatcher is what you need.

      But what exactly do you mean with "meta data" here ?

      BTW: The QMetaDataReaderControl class provides read access to the meta-data of a QMediaService's media

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dulajun
        wrote on 25 May 2013, 22:45 last edited by
        #3

        Never mind metadata, I want to append information to the file so I could depend on them when the file moved to different place.
        But if you know about software like Adobe Bridge you could in a Bridge browser to right click and choose "File Info..." and you will get information related to the file like "Document Title", "Author", "Description"...

        About QFileSystemWatcher, How many folders could I watch (the main folder and all his sub-folders)?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on 25 May 2013, 22:54 last edited by
          #4

          Append information to a file? Simply use QFile and open the file with QIODevice::Append flag :)

          As for meta data: It has a meaning on the File System level, where "meta data" refers to everything that is stored in the file system data structures, but is not the file's content. This would be the file's name, the file's size, the file attribute flags (e.g. "read only"), the list of data blocks assigned to that file, and so. Though, it seems you are talking about "meta data" like it's used for media files, e.g. "title", "artist", "album" and so on. That's actually data that is stored in the file. And it of course is specifc to the individual File Format! For example, the MP3 format does not have support for "meta data" by itself, but people have invented the ID3 Tag to workaround this limitation. Other file formats have other "ways" to embed meta information. So I don't think Qt has a class that can do it for any file format. You need to look up in the individual specifications of the individual file format how meta data, if support, has to be embedded. Then just use QFile, maybe with QDataStream, to write the data into the file...

          --

          About your QFileSystemWatcher question, the docs say this:

          The act of monitoring files and directories for modifications consumes system resources. This implies there is a limit to the number of files and directories your process can monitor simultaneously. On Mac OS X 10.4 and all BSD variants, for example, an open file descriptor is required for each monitored file. Some system limits the number of open file descriptors to 256 by default. This means that addPath() and addPaths() will fail if your process tries to add more than 256 files or directories to the file system monitor. Also note that your process may have other file descriptors open in addition to the ones for files being monitored, and these other open descriptors also count in the total. Mac OS X 10.5 and up use a different backend and do not suffer from this issue.

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dulajun
            wrote on 25 May 2013, 23:10 last edited by
            #5

            If I try to use QFile and open the file with QIODevice::Append flag, is this will corrupt the file and would be not available in it's application?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MuldeR
              wrote on 25 May 2013, 23:14 last edited by
              #6

              [quote author="dulajun" date="1369523401"]If I try to use QFile and open the file with QIODevice::Append flag, is this will corrupt the file and would be not available in it's application? [/quote]

              I don't understand that sentence.

              If you open a file with QFile and QIODevice::Append, it does nothing but opening the file in append mode. It does not corrupt anything. It only gives you the ability to append additional data to that file in the following. It's your obligation to append "meaningful" data to the file in the subsequent write() operations.

              Of course this is completely File Format specific...

              My OpenSource software at: http://muldersoft.com/

              Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

              Go visit the coop: http://youtu.be/Jay...

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dulajun
                wrote on 25 May 2013, 23:21 last edited by
                #7

                Like if I open a jpg or photoshop file and append some information. Then after closing the photoshop file will be available in Photoshop application and the application will keep the same information after saving the file?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MuldeR
                  wrote on 25 May 2013, 23:27 last edited by
                  #8

                  I still don't really understand.

                  Anyway: If you open a JPEG file to append or modify data, it should be clear that this requires a detailed understanding of the JPEG file format. That's because, if you append/modify an existing JPEG file, the new content of the file must be a valid JPEG file (according to the JPEG specification) again. As long as you make that sure, Photoshop (or whatever app that can read JPEG files) will be able to read the "modified" file. Otherwise not.

                  As for JPEG files and "meta information", I think Exif is what you are looking for:
                  http://www.cipa.jp/english/hyoujunka/kikaku/pdf/DC-008-2010_E.pdf

                  My OpenSource software at: http://muldersoft.com/

                  Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                  Go visit the coop: http://youtu.be/Jay...

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    crayon
                    wrote on 26 May 2013, 16:04 last edited by
                    #9

                    May I suggest instead a database or file that is always accessible to your application containing "metadata" about files that your application is monitoring.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dulajun
                      wrote on 26 May 2013, 17:38 last edited by
                      #10

                      I want to write information which are File ID, File Name and File Path.
                      And want these information to be stuck with the file, so I can compare the actual name and path with the appended name and path and determine where the file was.

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        dulajun
                        wrote on 31 May 2013, 00:45 last edited by
                        #11

                        Could you MuldeR please help me in modifying this snippet of code to append a text to the end of the file and then read that text from the end of the same file. The text has a length of 1024 unicode characters exactly.

                        // append 1024 letters
                        QFile myFile("/Users/dulajun/Documents/pages.indd");
                        myFile.open(QIODevice::Append);
                        QDataStream out(&myFile);
                        //Here the code
                        ...

                        //read from the end 1024 letters
                        myFile.open(QIODevice::ReadOnly);
                        QDataStream in(&myFile);
                        QString text; //to receive the text.
                        //Here the code

                        1 Reply Last reply
                        0

                        7/11

                        25 May 2013, 23:21

                        • Login

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