Inserting binary data via QSQL
How to insert binary data to table "test" from "database" with 2 columns text "name" and bin "pic"
开发者_StackOverflowQSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setUserName("user");
db.setPassword("pwd");
db.setPort(1234);
db.setDatabaseName("database");
You can have a look at http://www.java2s.com/Code/Cpp/Qt/UsingsqldatabasefromQt.htm snippets
First you need to open the DB db.open();
One way would be
QSqlQuery query;
query.prepare("INSERT INTO test (name, pic) "
"VALUES (:name, :pic)");
query.bindValue(":name", "Bart");
query.bindValue(":pic", "Bart.jpg");
query.exec();
精彩评论