Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Image Stored in the Database.

    Mobile and Embedded
    2
    2
    338
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      karthi shan last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion last edited by

        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.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • First post
          Last post