Convert bool to QString
Use QVariant!
From bool to QString:
bool bInput = false;
QString s = QVariant(bInput).toString();
From QString to bool:
QString s = "true";
bool bInUse = QVariant(s).toBool();
You can use the static QString::number
method - the bool will be implicitly cast to int to match the integer form of the static factory method, which returns a QString
containing 0
or 1
.
bool test = true;
QString s = QString::number(test);
qDebug() displays a bool variable as "true" or "false". If you want to get such a string you can change your code a little bit:
bool test = true;
QString boolText = test ? "true" : "false";