2 is SQL statement syntax error (from enum QSqlError::ErrorType).
Try:
query.prepare("INSERT INTO User (pk, name, psw) "
"VALUES (NULL, :name, :psw)");
query.bindValue( ":name", ui.RUserNameLineEdit->text() );
query.bindValue( ":psw",ui.RPassword->text() );
QSqlQuery query;
query.prepare("INSERT INTO User (pk, name, psw) "
"VALUES (NULL, :name, :psw)");
query.bindValue( ":name", ui.RUserNameLineEdit->text() );
query.bindValue( ":psw",ui.RPassword->text() );
To copy to clipboard, switch view to plain text mode
and also you should use QSqlDatabase for QSqlQuery object
db.setHostName("127.0.0.1");
db.setDatabaseName("testpay");
db.setUserName("mypay");
db.setPassword("test123");
if(db.open())
{
}
db = QSqlDatabase::addDatabase("QMYSQL", "_default_");
db.setHostName("127.0.0.1");
db.setDatabaseName("testpay");
db.setUserName("mypay");
db.setPassword("test123");
if(db.open())
{
QSqlQuery query(db);
}
To copy to clipboard, switch view to plain text mode
Bookmarks