Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. best way to remember informations about opened files
Forum Updated to NodeBB v4.3 + New Features

best way to remember informations about opened files

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
9 Posts 3 Posters 709 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.
  • T Offline
    T Offline
    tubbadu
    wrote on last edited by
    #1

    hello there! I'm writing a comics file reader, and I wanted to remember the index of the page of every file opened with my application. I used Settings to store the file path as key and the index as value, and it works well as long as the file remains in the same position.
    However, if the file is moved or renamed the application consider it as a new file, and if another (different) file is moved in the same position as it with the same name it may cause errors

    what is the best way to handle this? is there perhaps a way of creating like an hash of the file, and use it as a key?

    thanks in advance!

    JonBJ 1 Reply Last reply
    0
    • T tubbadu

      hello there! I'm writing a comics file reader, and I wanted to remember the index of the page of every file opened with my application. I used Settings to store the file path as key and the index as value, and it works well as long as the file remains in the same position.
      However, if the file is moved or renamed the application consider it as a new file, and if another (different) file is moved in the same position as it with the same name it may cause errors

      what is the best way to handle this? is there perhaps a way of creating like an hash of the file, and use it as a key?

      thanks in advance!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @tubbadu said in best way to remember informations about opened files:

      However, if the file is moved or renamed the application consider it as a new file, and if another (different) file is moved in the same position as it with the same name it may cause errors

      Indeed, nothing can allow for that and know that a file was renamed or whatever.

      is there perhaps a way of creating like an hash of the file, and use it as a key?

      If you really want to. Makes it slower to recognise, and you will have to keep the hash up-to-date if changes.

      T 1 Reply Last reply
      0
      • JonBJ JonB

        @tubbadu said in best way to remember informations about opened files:

        However, if the file is moved or renamed the application consider it as a new file, and if another (different) file is moved in the same position as it with the same name it may cause errors

        Indeed, nothing can allow for that and know that a file was renamed or whatever.

        is there perhaps a way of creating like an hash of the file, and use it as a key?

        If you really want to. Makes it slower to recognise, and you will have to keep the hash up-to-date if changes.

        T Offline
        T Offline
        tubbadu
        wrote on last edited by tubbadu
        #3

        @JonB thanks for your reply!

        Indeed, nothing can allow for that and know that a file was renamed or whatever.

        isn't possible to run some kind of algorithm that takes the file as input and outputs a string or something as a "fingerprint" of that file, ignoring its filename? For instance my file manager (Dolphin, which is Qt based) when moving a file in a directory with another file with the same name does something similar to what I'm looking for, it says "the files are identical" or "the files are different")

        the files I need to open are not bigger than 500Mb, do you think this operation will take too much time?

        jsulmJ JonBJ 2 Replies Last reply
        0
        • T tubbadu

          @JonB thanks for your reply!

          Indeed, nothing can allow for that and know that a file was renamed or whatever.

          isn't possible to run some kind of algorithm that takes the file as input and outputs a string or something as a "fingerprint" of that file, ignoring its filename? For instance my file manager (Dolphin, which is Qt based) when moving a file in a directory with another file with the same name does something similar to what I'm looking for, it says "the files are identical" or "the files are different")

          the files I need to open are not bigger than 500Mb, do you think this operation will take too much time?

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

          @tubbadu said in best way to remember informations about opened files:

          do you think this operation will take too much time?

          You can do it in two steps:

          1. Check the file sizes: if both files have different sizes they are different
          2. If size is same calculate hashes from the content of both files using https://doc.qt.io/qt-5/qcryptographichash.html and compare these hashes

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

          T JonBJ 2 Replies Last reply
          1
          • T tubbadu

            @JonB thanks for your reply!

            Indeed, nothing can allow for that and know that a file was renamed or whatever.

            isn't possible to run some kind of algorithm that takes the file as input and outputs a string or something as a "fingerprint" of that file, ignoring its filename? For instance my file manager (Dolphin, which is Qt based) when moving a file in a directory with another file with the same name does something similar to what I'm looking for, it says "the files are identical" or "the files are different")

            the files I need to open are not bigger than 500Mb, do you think this operation will take too much time?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @tubbadu said in best way to remember informations about opened files:

            the files I need to open are not bigger than 500Mb, do you think this operation will take too much time?

            0.5GB to read on opening is a fair size! Up to you, but I would not want to calculate a hash on the complete content, only on some "unique sample" from it.

            jsulmJ 1 Reply Last reply
            0
            • JonBJ JonB

              @tubbadu said in best way to remember informations about opened files:

              the files I need to open are not bigger than 500Mb, do you think this operation will take too much time?

              0.5GB to read on opening is a fair size! Up to you, but I would not want to calculate a hash on the complete content, only on some "unique sample" from it.

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

              @JonB said in best way to remember informations about opened files:

              only on some "unique sample" from it

              What is "unique sample"? :-)

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

              JonBJ 1 Reply Last reply
              0
              • jsulmJ jsulm

                @JonB said in best way to remember informations about opened files:

                only on some "unique sample" from it

                What is "unique sample"? :-)

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @jsulm
                Exactly (hence the "s)! What part indeed if you're not going to read the whole file? Maybe the start of OP's file types are all similar in the early blocks so that's not good? Maybe the ends change?

                1 Reply Last reply
                0
                • jsulmJ jsulm

                  @tubbadu said in best way to remember informations about opened files:

                  do you think this operation will take too much time?

                  You can do it in two steps:

                  1. Check the file sizes: if both files have different sizes they are different
                  2. If size is same calculate hashes from the content of both files using https://doc.qt.io/qt-5/qcryptographichash.html and compare these hashes
                  T Offline
                  T Offline
                  tubbadu
                  wrote on last edited by
                  #8

                  @jsulm

                  If size is same calculate hashes from the content of both files using https://doc.qt.io/qt-5/qcryptographichash.html and compare these hashes

                  that really looks like what I was looking for, thank you very much!

                  @JonB

                  0.5GB to read on opening is a fair size! Up to you, but I would not want to calculate a hash on the complete content, only on some "unique sample" from it.

                  that's an amazing idea! the files I'm reading are basically zip or rar archives of jpg, so I may just check the qcryptographichash of, let's say, the first and the last image plus the file size, and if they are all the same I can consider it as identical!

                  thanks to both, I'll try and post here the result!

                  1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @tubbadu said in best way to remember informations about opened files:

                    do you think this operation will take too much time?

                    You can do it in two steps:

                    1. Check the file sizes: if both files have different sizes they are different
                    2. If size is same calculate hashes from the content of both files using https://doc.qt.io/qt-5/qcryptographichash.html and compare these hashes
                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @jsulm said in best way to remember informations about opened files:

                    calculate hashes from the content of both files using https://doc.qt.io/qt-5/qcryptographichash.html

                    @tubbadu
                    I don't believe you need any kind of cryptographic hash for your purpose of hash-content-for-compare. I believe Qt gives you an adequate implementation for your purpose in e.g. uint qHash(const QByteArray &key, uint seed = 0).

                    1 Reply Last reply
                    0

                    • Login

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