Results 1 to 3 of 3

Thread: Store QPixmap in sqlite BLOB field

  1. #1
    Join Date
    Jun 2015
    Posts
    28
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Store QPixmap in sqlite BLOB field

    Hello,

    I'm trying to store an QPixmap picture in a sqlite BLOB field, but it not storing. I've already search on forum and google, but not shure about my problem. can someone help me?

    only the picture do not store on table

    Qt Code:
    1. QString file = QFileDialog::getOpenFileName(this, tr("Select an image"),".", tr("JPEG (*.jpg *jpeg)\n"
    2. "PNG (*.png)\n"
    3. "GIF (*.gif)\n"));
    4. QImage image = QImageReader (file).read();
    5. QPixmap pm = QPixmap::fromImage(image).scaled(ui->label1->width(), ui->label1->height());
    6. ui->label1->setPixmap(pm);
    7.  
    8. QString description = "picture description";
    9.  
    10. QSqlDatabase con = QSqlDatabase::addDatabase("QSQLITE");
    11. con.setDatabaseName(_DB);
    12. con.open();
    13.  
    14. QSqlQuery query;
    15. query.prepare("INSERT INTO pictures (picture, description) VALUES (?,?)"); // picture is a blob field
    16. query.bindValue(0,pm);
    17. query.bindValue(1,description);
    18. query.exec();
    To copy to clipboard, switch view to plain text mode 

    thanks!
    Juliano

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Store QPixmap in sqlite BLOB field

    First, you don't need to sue QImageReader explicitly, QImage::load will do that for you.

    Secondly, what you want to do is to store the pixel data into the database.
    So save the pixmap/image into a QByteArray and store that into the database.

    See QPixmap::save() and QImage::save() with a QBuffer as the QIODevice.

    Or consider storing the orignal file.

    Cheers,
    _

  3. #3
    Join Date
    Jun 2015
    Posts
    28
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Store QPixmap in sqlite BLOB field

    Yeah! Solved
    Thanks my friend!

Similar Threads

  1. Replies: 5
    Last Post: 25th July 2013, 21:56
  2. Replies: 10
    Last Post: 30th June 2011, 22:47
  3. Replies: 4
    Last Post: 16th June 2011, 14:49
  4. How to update BLOB field in a SQLite database ?
    By aircraftstories in forum Qt Programming
    Replies: 6
    Last Post: 8th April 2011, 20:45
  5. Replies: 1
    Last Post: 14th September 2009, 08:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.