Hello,
I'm trying to store an QPixmap picture in a sqlite BLOB field, but it not storing. I've already search on forum and google, but not shure about my problem. can someone help me?
only the picture do not store on table
QString file = QFileDialog::getOpenFileName(this, tr
("Select an image"),
".", tr
("JPEG (*.jpg *jpeg)\n" "PNG (*.png)\n"
"GIF (*.gif)\n"));
QPixmap pm
= QPixmap::fromImage(image
).
scaled(ui
->label1
->width
(), ui
->label1
->height
());
ui->label1->setPixmap(pm);
QString description
= "picture description";
con.setDatabaseName(_DB);
con.open();
query.prepare("INSERT INTO pictures (picture, description) VALUES (?,?)"); // picture is a blob field
query.bindValue(0,pm);
query.bindValue(1,description);
query.exec();
QString file = QFileDialog::getOpenFileName(this, tr("Select an image"),".", tr("JPEG (*.jpg *jpeg)\n"
"PNG (*.png)\n"
"GIF (*.gif)\n"));
QImage image = QImageReader (file).read();
QPixmap pm = QPixmap::fromImage(image).scaled(ui->label1->width(), ui->label1->height());
ui->label1->setPixmap(pm);
QString description = "picture description";
QSqlDatabase con = QSqlDatabase::addDatabase("QSQLITE");
con.setDatabaseName(_DB);
con.open();
QSqlQuery query;
query.prepare("INSERT INTO pictures (picture, description) VALUES (?,?)"); // picture is a blob field
query.bindValue(0,pm);
query.bindValue(1,description);
query.exec();
To copy to clipboard, switch view to plain text mode
thanks!
Juliano
Bookmarks