Search code examples
mysqlqtfingerprint

How to save an array of unsigned char to MySQL


Any idea on how to save an array of unsigned char to a field in MySQL database ? I'm considering BLOB, but how can I convert it to QByteArray and convert it back to an array of unsigned char when I want to ? BTW, I'm trying to save fingerprint data.


Solution

  • I managed to solve this using the codes below (copied directly from my project)

    
    struct fp {
        unsigned char Template[MAX_TEMPLATE_SIZE];
        int size;
    };
    

    
    // unsigned char to QByteArray
    QByteArray FingerPrint::charArrayToByteArray(fp fp0) {
    
        QByteArray ba;
        for (int i=0; i
    
    

    // QByteArray to unsigned char fp FingerPrint::byteToFp(QByteArray *ba) { fp fp0; for (int i=0; isize(); i++) { fp0.Template[i] = ba->at(i); } fp0.size = ba->size(); return fp0; }