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. Unable to generate MD5 of a QString
QtWS25 Last Chance

Unable to generate MD5 of a QString

Scheduled Pinned Locked Moved Solved General and Desktop
cryptoqcryptographichqstringhash
3 Posts 2 Posters 3.4k 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.
  • Q Offline
    Q Offline
    Qjay
    wrote on 26 Jun 2016, 16:50 last edited by
    #1

    I am facing problem in generating an MD5 of a QString

    QString hash_me = QString(QCryptographicHash::hash((png_links),QCryptographicHash::Md5).toHex());
                png_links = hash_me ;
    

    error that i am getting is :

     error: no matching function for call to 'QCryptographicHash::hash(QString&, QCryptographicHash::Algorithm)'
                 QString hash_me = QString(QCryptographicHash::hash((png_links),QCryptographicHash::Md5).toHex());
                                                                                                       ^
    
    J 1 Reply Last reply 26 Jun 2016, 16:54
    0
    • Q Qjay
      26 Jun 2016, 16:50

      I am facing problem in generating an MD5 of a QString

      QString hash_me = QString(QCryptographicHash::hash((png_links),QCryptographicHash::Md5).toHex());
                  png_links = hash_me ;
      

      error that i am getting is :

       error: no matching function for call to 'QCryptographicHash::hash(QString&, QCryptographicHash::Algorithm)'
                   QString hash_me = QString(QCryptographicHash::hash((png_links),QCryptographicHash::Md5).toHex());
                                                                                                         ^
      
      J Offline
      J Offline
      Joel Bodenmann
      wrote on 26 Jun 2016, 16:54 last edited by Joel Bodenmann
      #2

      The QCryptographicHash::hash() method doesn't operate on QString, it operates on QByteArray:

      QByteArray QCryptographicHash::hash(const QByteArray &data, Algorithm method)
      

      Therefore, you have to convert your QString to a QByteArray first. The QString class provides several methods for that such as:

      • QByteArray QString::toLatin1() const
      • QByteArray QString::toLocal8Bit() const
      • QByteArray QString::toUtf8() const

      As the method names indicate you will loose portability. You have to know which encoding you want to use.

      Industrial process automation software: https://simulton.com
      Embedded Graphics & GUI library: https://ugfx.io

      1 Reply Last reply
      1
      • Q Offline
        Q Offline
        Qjay
        wrote on 26 Jun 2016, 17:04 last edited by
        #3

        Thanks !! I just figured it out after reading Docs !!

        Thanks for replying (y)

        1 Reply Last reply
        0

        3/3

        26 Jun 2016, 17:04

        • Login

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