PDA

View Full Version : QSqlite store/retrieve QVariantList



gonzoboy!
4th December 2009, 01:53
Hi all,

I am storing large float arrays as BLOBs via QVariantList. I can store them fine (apparently), but how do I retrieve them?

QSqlQuery query;
QVariant v;
QVariantList vl;
bool r = true;
int s;

r = db.isOpen();

r = query.prepare("SELECT ticktimes FROM ticks");
r = query.exec();
r = query.first();

v = query.value(0);
r = v.isValid();
//cout << v.toInt(&r) << endl; // works OK for single int type
vl = v.toList();

doesn't do it.

TIA

Lykurg
4th December 2009, 06:28
what does v.type() says and how do you store the list in the database?

gonzoboy!
5th December 2009, 03:29
type() returns QString

stored by:
if(db.isOpen()){
result = query.prepare("INSERT INTO ticks "
"(id, year, month, day, dayofweek, ticktimes, closes, deltas)"
"VALUES (:id, :year, :month, :day, :dayofweek, :ticktimes, :closes, :deltas)");


query.bindValue(":id", id);
query.bindValue(":year", year);
query.bindValue(":month", mo);
query.bindValue(":day", day);
query.bindValue(":dayofweek", dayw);
query.bindValue(":ticktimes", t);
query.bindValue(":closes", v);
query.bindValue(":deltas", d);

result = query.exec();

with t,v,d being the arrays as QVariantLists

Lykurg
5th December 2009, 07:01
Have a had a look at your tables? What is inserted into database? On my side nothing. So you can't bind QValueLists. First convert them to a QString/bytearray and afterwards convert them back. (you can use QList operatrors << and >>)

gonzoboy!
5th December 2009, 18:26
You are correct, I was loading nothing into the db. Thanks for the help.