Results 1 to 14 of 14

Thread: QDataStream and QByteArray issue

Hybrid View

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

    Default Re: QDataStream and QByteArray issue

    after spending hours(!) and thanks to you guys I got what to do,taking a peek to my previous post when I noticed the size inconsistency I tried to encode the str2Store using str2Store.toHex();
    and then saved it into database and used the static method QByteArray::fromHex(str2recover);
    and decoded it and saved it in a QImage and it just works like a charm now

    I'm attaching the final code
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2010
    Posts
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QDataStream and QByteArray issue

    Hello to everybody,

    hoping to be helpful and to learn from everybody.

    m.


    Added after 1 20 minutes:


    Thanks for your code,
    I send you my revised version for POstgresql

    inserting :

    void lbytea()
    {
    QByteArray qba;

    QImage pix("/home/pgsql/loaddir/motrice_30.png","PNG");
    QBuffer buffer(&qba);
    buffer.open(QIODevice::WriteOnly);
    pix.save(&buffer,"PNG");
    QSqlQuery insertPicCom;
    insertPicCom.prepare("insert into pix (sch,pixyb) values(:sch,ixyb)");
    qba=qba.toHex();
    insertPicCom.bindValue(":sch","PIPPO");
    insertPicCom.bindValue("ixyb",qba);
    insertPicCom.exec();
    }

    retriving


    qstrpix="select anf_pixyb from anf_flotta where anf_idmezzo = ...
    QSqlQuery qpix(qstrpix);
    if (qpix.next()) {
    qba = qpix.value(0).toByteArray();
    qba=QByteArray::fromHex(qba);
    QPixmap dixy;
    dixy.loadFromData ( qba);
    qwh->setIcon(QIcon(dixy));
    }

    m.
    Last edited by magilda; 10th November 2010 at 23:32.

  3. #3

    Default Re: QDataStream and QByteArray issue

    QByteArray data = QByteArray::fromHex("200000008305370FFFFFF63050000 8E");
    QDataStream dataStreamToReadFrom(&data, QIODevice::ReadOnly);
    QByteArray convertedData;
    dataStreamToReadFrom >> convertedData;

    QString Str = data.toHex();
    QString convertedStr = convertedData.toHex();

    Here Str and convertedStr are not same. Why?

    I want to both QByteArray data and converted Data to be the same. How to achieve that.?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QDataStream and QByteArray issue

    Do not double post. Make one post, in one section of the forum only, and it will be read.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Apr 2021
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QDataStream and QByteArray issue

    CAN SOMEONE HELP ME!!? im using linux ubuntu
    Im getting this error
    fatal error: QTextStream: No such file or directory

    Qt Code:
    1. #include "QTextStream"
    2. #include <QDebug>
    3. QTextStream cin(stdin);
    4. QTextStream cout(stdout);
    5. QTextStream cerr(stderr);
    6. int main() {
    7. int num1(1234), num2(2345) ;
    8. cout << oct << num2 << '\t'
    9. << hex << num2 << '\t'
    10. << dec << num2
    11. << endl;
    12. double dub(1357);
    13. cout << dub << '\t'
    14. << forcesign << dub << '\t'
    15. << forcepoint << dub
    16. << endl;
    17. dub = 1234.5678;
    18. cout << dub << '\t'
    19. << fixed << dub << '\t'
    20. << scientific << dub << '\n'
    21. << noforcesign << dub
    22. << endl;
    23. qDebug() << "Here is a debug message with " << dub << "in it." ;
    24. qDebug("Here is one with the number %d in it.", num1 );
    25. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by d_stranz; 2nd April 2021 at 16:40. Reason: missing [code] tags

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QDataStream and QByteArray issue

    Use <QTextStream> not "QTextStream". #include with quotes only looks in the local directory.

    Please do not hijack a thread to make an unrelated post. Start a new thread.
    Last edited by d_stranz; 2nd April 2021 at 16:50.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Streaming QImage (QByteArray, QDataStream, QBuffer)
    By knarz in forum Qt Programming
    Replies: 5
    Last Post: 17th January 2009, 22:05
  2. QByteArray problem
    By Misenko in forum Qt Programming
    Replies: 17
    Last Post: 4th October 2008, 21:53
  3. Reading QByteArray from QDataStream Qt3.3
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 20: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.