Important: Please read the Qt Code of Conduct -

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;


    //image stored in the database
    void MainWindow::on_pushButton_clicked()
    QString img;
    PRINT<<"Connecting ....";
    QSqlDatabase myDB= QSqlDatabase::addDatabase("QSQLITE");

    if( 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...";
                  PRINT <<"user Error .." << qry.lastError().text();
                  PRINT <<"Closed";


    Any one help me how to image stored in the database and retrieve the image.

  • Lifetime Qt Champion

    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.

Log in to reply