Saving and retrieving an image using Qt

Actually, I found a useful article related to my problem, but not really, I will try more about the problem.

I have a table with id column identifiers as integer and pix as blob

I have a form with a label and two buttons open and save

I am trying to open an image in a label, then I need to save the database table when I click save

In addition, I want to get the image again to add a shortcut if I add navigation buttons as the next and previous.

Any help please?

+3
source share
1 answer

Here is a quick example of storing QImage in a database:

// Converting image to byte array:
QByteArray bytes;
{
    QBuffer buffer (&bytes);
    buffer.open (QBuffer::WriteOnly);
    image.save (&buffer, "PNG");
}

// Writing data into the database:
QString id_string = id == -1 ? "NULL" : QString::number (id);
QSqlQuery query ("REPLACE INTO images "
                 "(id, image) VALUES (:id, :image)");
query.bindValue (":id", id_string);
query.bindValue (":image", QString (bytes.toBase64()));
if (!query.exec()) throw some_exception;

, , SQL-, . , , , . , .

+2

Source: https://habr.com/ru/post/1780773/


All Articles