Hi, Il 26/01/21 16:52, Kevin André ha scritto:
When reading a zero BIT value from the database, this outputs: getBool called for: QVariant(QString, "\u0000") getBool will convert QVariant(QString, "\u0000") to bool true The docs of toBool() claim that toBool should return false for a string value of "0". I am using Qt version 5.12.3. So is this a mismatch between the Qt version of the docs and the Qt version that I am using? Or am I missing something else here?
You've been bit by a combination of two things, one is Qt not supporting the BIT column type natively (that's QTBUG-21326), and mapping it to a string. The other that the string you're getting contains a NUL (U+0000), not a literal 0 (U+0030). When converting a QVariant containing a string to bool, Qt maps empty strings, the string "0" and the string "false" (in any case) to false and everything else to true:
https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qvariant.cpp?h=5.12#n344
Therefore, work around the issue and do the conversion yourself. (An alternative would be using TINYINT to represent bools.)
HTH, -- Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer KDAB (France) S.A.S., a KDAB Group company Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com KDAB - The Qt, C++ and OpenGL Experts
smime.p7s
Description: Firma crittografica S/MIME
_______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest