retrieving images(blob) from sqlite db

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

retrieving images(blob) from sqlite db

Ali M
I've created a sqlite db with a blob field and put images in it. how can i retrieve the images and show them in a qtextbrowser? i want to get the images with a for loop something like the below code but i don't know how.

def readImage(self):
        cur = self.db.cursor()
        rows = cur.execute("select cover from covers")
        pm = QPixmap()
        for row in rows:
                pic = self.ui.label.setPixmap(QPixmap("row.jpg"))
                self.ui.textBrowser.insertFromMimeData(pic)

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: retrieving images(blob) from sqlite db

michael h


On Sat, Aug 24, 2019 at 4:39 AM Ali M <[hidden email]> wrote:
I've created a sqlite db with a blob field and put images in it. how can i retrieve the images and show them in a qtextbrowser? i want to get the images with a for loop something like the below code but i don't know how.

def readImage(self):
        cur = self.db.cursor()
        rows = cur.execute("select cover from covers")
        pm = QPixmap()
        for row in rows:
                pic = self.ui.label.setPixmap(QPixmap("row.jpg"))
                self.ui.textBrowser.insertFromMimeData(pic)

You can use loadFromData(thebytes) to load a QPixmap from bytes, however you may use a QImage (which also has loadFromData) and https://doc.qt.io/qt-5/qtextcursor.html#insertImage-3 because it looks easier to me

(insertFromMimeData won't work on a QPixmap anyhow AFAICT)


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt