PDA

View Full Version : QSqlQuery::bindValue



viglu
29th March 2010, 18:57
Hello,

I have a problem with the following lines.


QSqlQuery query(db);
query.prepare("INSERT INTO demo1 (id) VALUES (?)");

QUuid uuid = QUuid::createUuid();
query.bindValue(0, uuid.toString());

I receive the error
error: no matching function for call to ‘QSqlQuery::bindValue(int, QString)

But I don't know why. Can anyone help me ?

Regards,
Luc

Lykurg
29th March 2010, 20:02
Make sure you have QT += sql in your pro file and you have included the QSqlQuery header in your file.

toutarrive
29th March 2010, 20:05
error: no matching function for call to ‘QSqlQuery::bindValue(int, QString)
There is no such function QSqlQuery::bindValue(int, QString) in Qt.
You have to use a QVariant instead of a QString.
The correct signature of the bindValue function is :

QSqlQuery::bindValue ( int pos, const QVariant & val, QSql::ParamType paramType = QSql::In )
try this:

query.bindValue(0,QVariant( uuid.toString() ) );

Lykurg
29th March 2010, 20:13
You can use the code. It works perfect for me because Qt casts a QString to a QVariant!