Image Stored in the Database.
-
Hi All,
I developed one application, user selected image need to appeared in the label button, then if I click push-button that image need to store in database.
image only appeared in the label. I cant able to directly stored in the database.
Here is my code:
//image appeared in the label button
void MainWindow::on_pushButton_4_clicked()
{
QString fileName = "/home/embdestech/Desktop/drink.png";qDebug() <<fileName<<endl; ui->label_2->setPixmap(fileName);
}
//image stored in the database
void MainWindow::on_pushButton_clicked()
{
QString img;
//img=ui->lineEdit->text();
//addr=ui->lineEdit_2->text();
PRINT<<"Connecting ....";
QSqlDatabase myDB= QSqlDatabase::addDatabase("QSQLITE");
myDB.setDatabaseName("/home/Desktop/tsk/karthick.db");if(myDB.open())//opening database { PRINT <<"Database Opened..."; QSqlQuery qry; if(qry.exec("CREATE TABLE sen(img VARCHAR[20]);")) { PRINT <<"karthick Table Created..."; } PRINT<<QString("INSERT INTO sen(img) VALUES('%1');").arg(img); if(qry.exec(QString("INSERT INTO sen(img) VALUES('%1');").arg(img))) { PRINT <<"values inserted..."; } else { PRINT <<"user Error .." << qry.lastError().text(); PRINT <<"Closed"; myDB.close(); } myDB.close();
}
}Any one help me how to image stored in the database and retrieve the image.
-
Why are you creating the table each time you try to store the image?
In the code you provided you commented out//img=ui->lineEdit->text();
that means you're trying to store an empty string.