Results 1 to 5 of 5

Thread: QSqlite store/retrieve QVariantList

  1. #1
    Join Date
    Nov 2009
    Posts
    10
    Thanks
    2

    Default QSqlite store/retrieve QVariantList

    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
    Last edited by gonzoboy!; 4th December 2009 at 02:40. Reason: reformatted to look better

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: QSqlite store/retrieve QVariantList

    what does v.type() says and how do you store the list in the database?

  3. #3
    Join Date
    Nov 2009
    Posts
    10
    Thanks
    2

    Default Re: QSqlite store/retrieve QVariantList

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: QSqlite store/retrieve QVariantList

    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 >>)

  5. The following user says thank you to Lykurg for this useful post:

    gonzoboy! (5th December 2009)

  6. #5
    Join Date
    Nov 2009
    Posts
    10
    Thanks
    2

    Default Re: QSqlite store/retrieve QVariantList

    You are correct, I was loading nothing into the db. Thanks for the help.

Similar Threads

  1. QVariantList from QScript?
    By musla in forum Qt Programming
    Replies: 0
    Last Post: 29th June 2009, 10:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.