Results 1 to 14 of 14

Thread: QDataStream and QByteArray issue

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    Join Date
    Apr 2008
    Location
    Karaj,Iran
    Posts
    43
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    12

    Default Re: QDataStream and QByteArray issue

    Quote Originally Posted by seneca View Post
    I guess you need to create the QDataStream after filling str2recover.

    Reason: At the time you currently create the datasteam in your sample, the byte array is empty and the stream will have status ReadPastEnd instead of Ok
    I did that but still no luck,BTW I noticed that the way I save the picture in the database takes much more space than the image size itself,I changed it to following and the size of the blob is the same as the picture now
    Qt Code:
    1. QByteArray str2Store;
    2. QImage pix("c:/parva.jpg","JPEG");
    3. QBuffer buffer(&str2Store);
    4. buffer.open(QIODevice::WriteOnly);
    5. pix.save(&buffer,"JPEG");
    6. QSqlQuery insertPicCom(QString("insert into pix values(?)"));
    7. insertPicCom.bindValue(0,str2Store);
    8. insertPicCom.exec();
    To copy to clipboard, switch view to plain text mode 
    but I still have problem how to reverse the process and retrieve the picture from database into a QImage,Any ideas?

    PS:
    I noticed that the size of QByteArray I save in database is 3056 bytes but when I retrieve it from database and put it in another QByteArray it's 5464 bytes which means sth like a header or .. has been added to it,how can I turn it to the original QByteArray?
    Last edited by sepehr; 31st January 2009 at 18:09.

Similar Threads

  1. Streaming QImage (QByteArray, QDataStream, QBuffer)
    By knarz in forum Qt Programming
    Replies: 5
    Last Post: 17th January 2009, 23:05
  2. QByteArray problem
    By Misenko in forum Qt Programming
    Replies: 17
    Last Post: 4th October 2008, 22:53
  3. Reading QByteArray from QDataStream Qt3.3
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 21:23

Tags for this Thread

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.