Inserting blob into mysql using QT?
Hi,
I am not so strong in mysql/sql and have this, hopefully, easy question:
How to store/read a .png file in mysql database using Qt.
I have a table containing 2 columns: snap_time,snap; (datetime,blob)
I tried this, but I get an error:
Code:
out << _pixmap.toImage();
buffer.close();
query.prepare("insert into memos(snap,snap_time) values (:snap, :time)");
query.bindValue(":snap",bArray->constData());
query.bindValue(":time",_time.toString("yyyy-MM-dd hh:mm:ss"));
if(!query.exec())
Thank you for help
Re: Inserting blob into mysql using QT?
Re: Inserting blob into mysql using QT?
can you change line 10 to :
Code:
query.bindValue(":time",_time.toString("yyyyMMddhhmmss"));
1 Attachment(s)
Re: Inserting blob into mysql using QT?
i create a class to manage BLOB fields. i tested in SQLITE and FIREBIRD. i think must work in MYSQL
Code:
class SqlFieldBlob
: public QObject{
Q_OBJECT
public:
explicit SqlFieldBlob
(QObject *parent
= 0);
bool saveData
(const QString &filename
);
public slots:
void setData
(const QByteArray &byteArray
) { p_byteArray
= byteArray;
} void setFileName
(const QString &filename
);
void setPixmap
(const QPixmap &pixmap
);
private:
};
and using something like
Code:
SqlFieldBlob blob;
blob.setFileName(fileName);
query2.prepare("INSERT INTO files (file_name, file_data) "
"VALUES (:id, :id2)");
query2.bindValue("id", fileName);
query2.bindValue("id2", blob.data());
query2.exec();
Re: Inserting blob into mysql using QT?
code to convert a QPixmap in a QByteArray
Code:
{
pixmap.save(&buffer, "PNG");
return buffer.data();
}