[Qt-interest] how to write data into file

Atlant Schmidt aschmidt at dekaresearch.com
Tue Oct 11 15:29:02 CEST 2011


Vincent:

  The code you included is taking integers in three different sizes
  (1 byte, 2 byte, and 4 byte), formatting them for printout as
  hexadecimal numbers and concatenating them into a single
  QString, and then writing that complete QString (containing the
  three numbers) to a file.

  Perhaps you're really looking for QDataStream?

    http://doc.qt.nokia.com/latest/qdatastream.html

  *THAT* class can write binary data to a file.

                                         Atlant


From: qt-interest-bounces+aschmidt=dekaresearch.com at qt.nokia.com [mailto:qt-interest-bounces+aschmidt=dekaresearch.com at qt.nokia.com] On Behalf Of Vincent Cai
Sent: Tuesday, October 11, 2011 08:36
To: Qt-interest
Subject: [Qt-interest] how to write data into file

Dear all,

         I try to write some different type of data into a file, but failed.
         From below code, what I hope to get in file is: 01 00 02 00 00 00 03
         But what I exactly get is: 123
         Could anybody tell me how to modify below code?

    QFile TSAFile;
    QString tmp;
    const QChar *data;
    quint8 a = 0x01;
    quint16 b = 0x02;
    quint32 c = 0x03;
    tmp += QString::number(a, 16);
    tmp += QString::number(b, 16);
    tmp += QString::number(c, 16);
    data = tmp.constData();
    while (!data->isNull())
    {
        TSAFile.write((char*)data);
        ++data;
    }
    TSAFile.setFileName("C:\\QtDebug.bin");
    TSAFile.close();

Thanks,
Vincent.

________________________________
This message and any attachments may contain Cypress (or its subsidiaries) confidential information. If it has been received in error, please advise the sender and immediately delete this message.


Click here<https://www.mailcontrol.com/sr/4PD3vNvtM43TndxI!oX7UpIgRUnoDh5v3XkRp7nHLTpcbWRiNosiY0X!HI0WOQqu!XVREiuPj!pmYIqzE2R4VA==> to report this email as spam.

________________________________
This e-mail and the information, including any attachments, it contains are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.

Thank you.

Please consider the environment before printing this email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20111011/57ea2421/attachment.html 


More information about the Qt-interest-old mailing list