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 get md5 of an image in QML?
Forum Updated to NodeBB v4.3 + New Features

How to get md5 of an image in QML?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 768 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.
  • NineswissN Offline
    NineswissN Offline
    Nineswiss
    wrote on last edited by
    #1

    I have image thumbnails stored as their md5 hash eg. fc00082dcdb3c5924f96e0b35773e182.jpg.
    This way I can access them even if they are moved in the system.
    Then in QML when I load an image/images I want to look up their md5 hash and then load the appropriate thumbnail.
    So far I have had no luck. I have tried:

    Qt.md5(fileUrl)
    

    and

    Qt.md5(imageid.source)
    

    But they are not correct. The images are displayed in gridview btw.
    Any ideas?

    Christian EhrlicherC 1 Reply Last reply
    0
    • NineswissN Nineswiss

      I have image thumbnails stored as their md5 hash eg. fc00082dcdb3c5924f96e0b35773e182.jpg.
      This way I can access them even if they are moved in the system.
      Then in QML when I load an image/images I want to look up their md5 hash and then load the appropriate thumbnail.
      So far I have had no luck. I have tried:

      Qt.md5(fileUrl)
      

      and

      Qt.md5(imageid.source)
      

      But they are not correct. The images are displayed in gridview btw.
      Any ideas?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Nineswiss said in How to get md5 of an image in QML?:

      Then in QML when I load an image/images I want to look up their md5 hash and then load the appropriate thumbnail.

      Then you have to load the real image data, calculate the md5 hash sum so you know the filename.

      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
      • NineswissN Offline
        NineswissN Offline
        Nineswiss
        wrote on last edited by
        #3

        @Christian-Ehrlicher So that means doing it in C++ I would imagine?

        Christian EhrlicherC 1 Reply Last reply
        0
        • NineswissN Nineswiss

          @Christian-Ehrlicher So that means doing it in C++ I would imagine?

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Nineswiss It maybe also works with qml but I would guess it's faster and easier with c++ - QFile and QCryptoGraphicHash are your friends.

          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
          • NineswissN Offline
            NineswissN Offline
            Nineswiss
            wrote on last edited by
            #5

            @Christian-Ehrlicher Damn, I was hoping to find away to avoid C++ for this as I am very new to it. Oh well!

            1 Reply Last reply
            0
            • NineswissN Offline
              NineswissN Offline
              Nineswiss
              wrote on last edited by
              #6

              SOLVED!
              getmd5.h

              #ifndef GETMD5_H
              #define GETMD5_H
              
              #include <QFile>
              #include <QCryptographicHash>
              
              class GetMd5 : public QObject
              {
                  Q_OBJECT
              
              public slots:
              
              QString getMd5(const QString &filepath)
              {
                  QFile file(filepath);
                  file.open(QIODevice::ReadOnly);
                  QCryptographicHash md5(QCryptographicHash::Md5);
                  while(!file.atEnd())
                  {
                      md5.addData(file.read(8192));
                  }
                  QString Md5Str = md5.result().toHex();
                  file.close();
                  return Md5Str;
              }
              
              public:
                  GetMd5() {}
              };
              
              #endif // GETMD5_H
              

              myqml.qml

              getMd5.getMd5(fileUrl) //Minus 'file//
              

              Thanks for the help @Christian-Ehrlicher !

              1 Reply Last reply
              1
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                I would increase the buffer size a little bit - maybe 1MB or so. Otherwise there are a lot of small read operations for nothing.

                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

                • Login

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