For file-to-database path, don't use QPixmap or QImage or anything like that. Use QFile::readAll to read bytes from file into a QByteArray, then QByteArray::data() and sqlite3_bind_blob (or equivalent in your SQLite wrapper, which I'm not familiar with) to bind the data to a SQL statement.

When reading the data from the database, run a select statement and obtain raw data pointer with sqlite_column_blob (or equivalent). Then transfer it into a QPixmap by means of QPixmap::loadFromData.

Igor Tandetnik

On 11/6/2013 1:42 PM, Ulrich Goebel wrote:
Hallo again,

now I have to handle pictures. In a SQLite database I would like to save
pictures from people. So I made a table

CREATE table pictures (id integer, pic blob)

With PyQT4 I build a formular where I want to show the pictures. (In
fact the formular shows data from a person, and even a picture of a
person.) I use a QtGui.QLabel as the widget, which takes alternativly
text or a pixmap. The workflow is:

1. Get the picture from a file, let's say pic.jpg, an show it in the
label. That is done by
    pic = QtGui.QPixmap("pic.jpg")...
    Label.setPixmap(pic)   # a method of the QtLabel.
That works, the picture is shown.

2. Store the picture in the database. I tried
    pixmap = Label.getPixmap()
    sql = "INSERT into pictures (pic) values (?)"
    cursor.execute(sql, (pixmap,))
That doesn't work, it ends with "TypeError: Bad binding argument type
supplied - argument #2: type QPixmap".

3. Get the picture back from the database. It should be something like
    sql = "SELECT pic from pictures"
    pixmap = cursor.execute(sql)... # yes, I know, that doesn't work,
                                    # but in a way we get pixmap set to
                                    # the pic column from some row
    Label.setPixmap(pixmap)

As You can see, the second step doesn't work, for the third I don't have
any idea. It seems to be a problem of type-conversion betwenn blob
(SQLite) and QPixmap (Qt, python) in both directions.

By the way: Even Qt has a QtSql module, but for the moment I prefere to
use the apsw module...

Every hint is welcome!

Ulrich




_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to