Am 26.01.2021 um 16:52 schrieb Kevin André:
Hi,

I am reading a boolean value from a database column with SQL type
"BIT" in MySQL. But I discovered that when a zero is stored in that
column, my program apparently interprets that zero value as a boolean
true value. I traced the problem to the QVariant->bool conversion:

bool Database::getBool(QVariant v, bool nullValue)
{
     qDebug() << "getBool called for:" << v;
     if (v.isNull())
         return nullValue;

     qDebug() << "getBool will convert" << v << "to bool" << v.toBool();
     return v.toBool();
}

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".
But your string is not "0" - it's "\0".


Christian
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to