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 insert in statically in database:
Forum Updated to NodeBB v4.3 + New Features

Image insert in statically in database:

Scheduled Pinned Locked Moved Mobile and Embedded
9 Posts 3 Posters 3.1k Views 2 Watching
  • 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 12 Oct 2015, 06:01 last edited by
    #1

    Hi All,

    How to image insert statically in the sqlite database. i can able to insert dynamically only. If i given image path, at run time path(string) only came, image doesn't appeared. anyone help me.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 12 Oct 2015, 22:23 last edited by
      #2

      Hi,

      How are you inserting the image in the database ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        karthi shan
        wrote on 13 Oct 2015, 10:16 last edited by
        #3

        Hi,

        Here is image inserting code, I need to image insert in the Sqlite table, how to image insert directly in the Sqlite table.

        QFile file("/home/Desktop/image/food.png");
        if(myDB.open())//opening database
        {
        PRINT <<"Database Opened...";
        if (!file.open(QIODevice::ReadOnly)) return;
        QByteArray byteArray = file.readAll();
        QSqlQuery qry;
        qry.exec("CREATE TABLE images(id integer primary key autoincrement, img BLOB);");
        {
        PRINT <<"images Table Created...";
        }
        QSqlQuery query;
        query.prepare("INSERT INTO images(img) VALUES (?)");
        query.addBindValue(byteArray);
        query.exec();
        PRINT <<"values inserted...";
        qDebug()<<byteArray;
        }

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 13 Oct 2015, 10:48 last edited by
          #4

          I'm not a SQLite expert, but maybe you have to commit the change?

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 13 Oct 2015, 21:10 last edited by
            #5

            How do you read the image back ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            K 1 Reply Last reply 17 Oct 2015, 06:23
            0
            • S SGaist
              13 Oct 2015, 21:10

              How do you read the image back ?

              K Offline
              K Offline
              karthi shan
              wrote on 17 Oct 2015, 06:23 last edited by
              #6

              @SGaist

              Hi,
              Here image read code is here:

              void MainWindow::on_pushButton_3_clicked()
              {
              int id;

              if(myDB.open())//opening database
              {
                  QByteArray array;
                  QSqlQuery query("SELECT img FROM images");
                  while(query.next())
                  {
                      for( int i =1; i <= 2; i++ )
                      {
                          array = query.value(1).toByteArray();
                          qDebug()<<0;
                          id=query.value(0).toInt();
                          qDebug()<<array;
                          QPixmap pixmap = QPixmap();
                          pixmap.loadFromData(array);
                          if (id==11)
                          {
                              ui->label_2->setPixmap(pixmap);
                          }
                          if(id==10)
                          {
                              ui->label_3->setPixmap(pixmap);
                          }
                          if(id==12)
                          {
                              ui->label->setPixmap(pixmap);
                          }
                          if(id==11)
                          {
                              ui->label_5->setPixmap(pixmap);
                          }
              
                          ui->label_4->setNum(id);
                          qDebug()<<id;
                      }
                  }
              }
              

              }

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 17 Oct 2015, 21:51 last edited by
                #7

                Your select statement only asks for img, there's no id returned. And why the for loop ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                K 1 Reply Last reply 20 Oct 2015, 05:38
                0
                • S SGaist
                  17 Oct 2015, 21:51

                  Your select statement only asks for img, there's no id returned. And why the for loop ?

                  K Offline
                  K Offline
                  karthi shan
                  wrote on 20 Oct 2015, 05:38 last edited by
                  #8

                  @SGaist

                  Image insert and fetching its working, But at the time i can able to store one image only. i need to store multiple image at the time. single image insert and fetching its working fine.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 20 Oct 2015, 20:08 last edited by
                    #9

                    If you want to insert several images, you need to create a list of image, loop through it to insert them.

                    If you want to show them all at once, then create as many QLabel you need in the loop reading the results.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0

                    1/9

                    12 Oct 2015, 06:01

                    • Login

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