Results 1 to 6 of 6

Thread: Help!!

  1. #1
    Join Date
    Aug 2013
    Posts
    5
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question Help!!

    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
    Last edited by rqi115; 4th December 2013 at 07:27.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    506
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help!!

    Hi, please show us what you have already tried.

    Ginsengelf

    PS: very informative thread title...

  3. #3
    Join Date
    Aug 2013
    Posts
    5
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help!!

    Quote Originally Posted by Ginsengelf View Post
    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
    Last edited by rqi115; 4th December 2013 at 08:26.

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Help!!

    how to parsing QByteArray to some of Int??
    QByteArray::toInt

  5. #5
    Join Date
    Aug 2013
    Posts
    5
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help!!

    Quote Originally Posted by stampede View Post
    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 ??

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help!!

    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,
    _

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.