PDA

View Full Version : Help!!



rqi115
4th December 2013, 07:18
i want select blob column on database table.

the data on blob column is QByteArray, help me read blob column and parsing that data into integer then show on textedit and combobox.

Thanks :D

Ginsengelf
4th December 2013, 07:37
Hi, please show us what you have already tried.

Ginsengelf

PS: very informative thread title...

rqi115
4th December 2013, 08:11
Hi, please show us what you have already tried.

Ginsengelf

PS: very informative thread title...

this my first time, posting on qtcentre hehe


struct edit_setting_param param;
.
.

param.edit_lp = ui->edit_lp->text().toInt();
param.edit_hp = ui->edit_hp->text().toInt();
param.edit_lines = ui->combo_lines->currentIndex();
param.edit_avg = ui->edit_avg->text().toInt();
param.edit_window = ui->combo_window->currentIndex();
param.edit_pp = ui->combo_pp->currentIndex();


QByteArray bytes((char *) &param, sizeof (param));

/* Insert into database */
pQ->prepare("insert into parameter (nama_param, id_tipe, id_unit, tag, note, setting) values (?, ?, ?, ?, ?, ?)");

pQ->bindValue(0, s_item.toAscii().data());
pQ->bindValue(1, s_id);
pQ->bindValue(2, id_select);
pQ->bindValue(3, s_init.toAscii().data());
pQ->bindValue(4, s_note.toAscii().data());
pQ->bindValue(5, bytes);



Now I want to show the BLOB data on Text Edit & Combo Box.

proses_q(Q, "select setting from parameter");
QByteArray data1 = Q->value(0).toByteArray();

qDebug() << data1.size() << data1;

//debug Ouput : 252 ". (i can't show the BLOB / QByteArray data on debug) --> how to parsing QByteArray to some of Int??


thank you :D

stampede
4th December 2013, 08:16
how to parsing QByteArray to some of Int??
QByteArray::toInt (http://qt-project.org/doc/qt-5.0/qtcore/qbytearray.html#toInt)

rqi115
4th December 2013, 08:32
QByteArray::toInt (http://qt-project.org/doc/qt-5.0/qtcore/qbytearray.html#toInt)

struct edit_setting_param param;

.
.

param.edit_lp = ui->edit_lp->text().toInt();
param.edit_hp = ui->edit_hp->text().toInt();
param.edit_lines = ui->combo_lines->currentIndex();
param.edit_avg = ui->edit_avg->text().toInt();
param.edit_window = ui->combo_window->currentIndex();
param.edit_pp = ui->combo_pp->currentIndex();

qDebug() << qDebug() << param.edit_lp << param.edit_hp << param.edit_lines << param.edit_avg << param.edit_window << param.edit_pp;
// debug output : 5 1000 4 5 0 0


QByteArray bytes((char *) &param, sizeof (param));

/* Insert into database */
pQ->prepare("insert into parameter (nama_param, id_tipe, id_unit, tag, note, setting) values (?, ?, ?, ?, ?, ?)");

pQ->bindValue(0, s_item.toAscii().data());
pQ->bindValue(1, s_id);
pQ->bindValue(2, id_select);
pQ->bindValue(3, s_init.toAscii().data());
pQ->bindValue(4, s_note.toAscii().data());
pQ->bindValue(5, bytes);


Now I want to show the BLOB data on Text Edit & Combo Box.

proses_q(Q, "select setting from parameter");
QByteArray data1 = Q->value(0).toByteArray();

bool ok;

qDebug() << data1.size() << data1.toInt(&ok, 16);
//debug output : 252 0.

the data value that I inserted to database is : 5 1000 4 5 0 0 , But when I selected data from database is : 0 ??

anda_skoa
4th December 2013, 09:31
Your code reinterprets an in-memory data structure as an array of bytes, so obviously you have to do it the other way around when "reading".

In general a very bad style and highly unportable.

Better serialize the values using some format, then deserialize on reading.

Cheers,
_