[Interest] Qt Sql BLOB data converting

Tony Rietwyk tony at rightsoft.com.au
Mon Nov 28 09:16:38 CET 2022

Hi Yauheni,

You don't say which type of database you are using?  There may be issues 
with the database client library altering the blob to UTF8.  Though I 
would expect the python code using the same client to have the same 

Assuming that QVariant has the byte array unaltered, then 
QVariant.toByteArray().length() should give 34.  Using qstrlen, suggests 
that you are using QVariant.toString instead.  To print the hex you 
should just use QVariant.toByteArray().toHex().

Hope that helps,


On 28/11/2022 6:46 pm, Yauheni Pervenenka via Interest wrote:
> Hello, community
> I have faced with issue that qvariant using qstrlen for getting data 
> size, but sometimes it returns wrong size especially for BLOB data(if 
> there are some special symbols), are there any way to get data correct?
> Note:
> Database value 34, python returns correct data size, but 
> qvariant::toByteArray returns 52
> Python data and Database data in hex(size 
> 68): 763130492d46ab4c9c7bb0e9789b29c3ab1e4723dea6c8e5d2f9b266a275e1fbe4a6
> Qt data in hex(size 104):
> 763130492d46c2ab4cc29c7bc2b0efbfbd78c29b29c3ab1e4723dea6efbfbdefbfbdefbfbdefbfbd66c2a275efbfbdefbfbdc4a6
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest

More information about the Interest mailing list