Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Image Stored in the Database.
QtWS25 Last Chance

Image Stored in the Database.

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 2 Posters 446 Views
  • 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 Offline
    K Offline
    karthi shan
    wrote on last edited by
    #1

    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
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved