Take the 2-minute tour ×

I am trying to insert a character into a column of a table. Instead, the decimal code of the character is inserted. How can I insert the character?


QString insertSql;
    .append("INSERT INTO ")
    .append(" table ")
    .append(" (direction) ")
    .append("VALUES (?)");
QSqlQuery update;

update.bindValue(0, 'F');

bool ex = update.exec();
qDebug() << update.lastError().type() << endl;
qDebug() << update.lastError().databaseText() << endl;
qDebug() << update.lastError().driverText() << endl;

If the direction attribute in the table is varchar, I get string '70' (decimal code of the character) inserted, if the attribute 'char' is then an error is produced, that the type is too short to store the value.


share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

In the call to bindValue, the second argument is a QVariant, but QVariant doesn't have a constructor accepting a char. Your char probably is converted to an int as this is a standard conversion, and not QChar. Your QVariant is an integer type and converted to a string during bindValue.

You can try explicitly using QChar :

update.bindValue(0, QChar('F'));
share|improve this answer
add comment

Your Answer


