Results 1 to 4 of 4

Thread: QSqlQuery::bindValue

  1. #1
    Join Date
    Mar 2010
    Location
    Luxembourg
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QSqlQuery::bindValue

    Hello,

    I have a problem with the following lines.

    Qt Code:
    1. QSqlQuery query(db);
    2. query.prepare("INSERT INTO demo1 (id) VALUES (?)");
    3.  
    4. QUuid uuid = QUuid::createUuid();
    5. query.bindValue(0, uuid.toString());
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSqlQuery::bindValue

    Make sure you have QT += sql in your pro file and you have included the QSqlQuery header in your file.

  3. #3
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQuery::bindValue

    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 :
    Qt Code:
    1. QSqlQuery::bindValue ( int pos, const QVariant & val, QSql::ParamType paramType = QSql::In )
    To copy to clipboard, switch view to plain text mode 
    try this:
    Qt Code:
    1. query.bindValue(0,QVariant( uuid.toString() ) );
    To copy to clipboard, switch view to plain text mode 
    Last edited by toutarrive; 29th March 2010 at 20:15.

  4. The following user says thank you to toutarrive for this useful post:

    viglu (29th March 2010)

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSqlQuery::bindValue

    You can use the code. It works perfect for me because Qt casts a QString to a QVariant!

Similar Threads

  1. QSqlquery
    By codeman in forum Qt Programming
    Replies: 10
    Last Post: 4th June 2009, 12:57
  2. what is going on a QSqlQuery?
    By mismael85 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2008, 13:35
  3. QSqlQuery problem
    By MarkoSan in forum Qt Programming
    Replies: 14
    Last Post: 14th January 2008, 22:50
  4. QSqlQuery problem
    By MarkoSan in forum Qt Programming
    Replies: 11
    Last Post: 18th December 2007, 13:25
  5. QSqlQuery error
    By skuda in forum Qt Programming
    Replies: 2
    Last Post: 2nd November 2007, 08:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.