0

I have a qsqlite which has a column contains raw data.

The codes

QByteArray data= query.value("data").toString().toLatin1();

or

QByteArray data= query.value("data").toByteArray();

give the exact same results which are correct except for some values. Certain bytes in the original data ara being converted into 0x3F. (I think values greater then a certain value)

The code below gives a result beyond far the real data.

data= query.value("data").toString().toUtf8()

What is the thing I'm missing?

--- Edit (example data has been added)

Real raw data in sqlite :

01 a4 81 1c 20 02 00 ff

query.value("data").toString().toByteArray() 

gives:

01 a4 81 1c 20 02 00 3f

query.value("data").toString().toUtf8() 

gives:

01 c2 a4 c2 81 1c 20 02 00 ef bf bd

By the way, the type of raw data I'm talking about is BLOB in sqlite database.

mehmetfa
  • 199
  • 3
  • 15

1 Answers1

1

Take a look at the documentation of QString::toLatin1(). It is undefined if the input string contains non-Latin1 characters. I guess this is the reason why certain values are replaced with 0x3f (which is '?' in ASCII).

Do you know if the raw data originally represented a character sequence in any encoding? Otherwise, I guess it doesn't make much sense to convert the raw byte sequence into a specific string encoding. You could try and take a look at different string encodings.

julians
  • 71
  • 5
  • I can read the data by python if I set connection text_factory to bytes. The problem with Qt I cannot find a way to do the same thing. Qt insists on geting BLOB as QString not as byteArray. By the way, raw data doesn't represent a string in any encoding. It's just raw data. – mehmetfa Mar 12 '19 at 06:35