QSqlQuery q(QSqlDatabase::database()); QByteArray ba; QDataStream ds(&ba,QIODevice::WriteOnly); QЛюбойКласс qkl(...); ds<<qkl; q.prepare("Update Таблица set поле = ? where ..."); q.addBindValue(QVariant(ba.toHex())); q.exec();
QSqlQuery sql(QSqlDatabase::database()); sql.exec("select id, поле from Таблица"); while (sql.next()) { QByteArray ba = QByteArray::fromHex(sql.value(1).toByteArray()); QDataStream ds(ba); QЛюбойКласс kls; ds>>kls; эземпляр_QMap[sql.value(0).toInt()]=kls; }
class MyQtClass : public QWiget{public:// some publicprivate: QTableWiget *m_table;};MyQtClass::MyQtClass (QWiget *parent = 0):QWiget(parent){ m_table = new QTableWiget(this);}
CREATE TABLE "public"."tst6" ( "ind" INTEGER NOT NULL, "pict" BYTEA, CONSTRAINT "tst6_pkey" PRIMARY KEY("ind")) WITHOUT OIDS;
QSqlQuery query; QLabel * tstLabel = new QLabel("label", this); tstLabel->setPixmap(QPixmap(":/db/resources/delete_record.jpg")); query.prepare("update public.tst6 set pict = ?"); query.addBindValue(QVariant(tstLabel->pixmap()).toByteArray()); query.exec();
bool save(QIODevice * device, const char * format = 0, int quality = -1) const
QSqlQuery query; QLabel * tstLabel = new QLabel("label", this); tstLabel->setPixmap(QPixmap(":/db/resources/delete_record.jpg")); QByteArray imgBuffer; tstLabel->pixmap().save(imgBuffer, "PNG"); query.prepare("update public.tst6 set pict = ?"); query.addBindValue(imgBuffer); query.exec();
tstLabel->pixmap().save(&imgBuffer, "PNG");