G
G
Gena2015-06-18 10:20:00
Qt
Gena, 2015-06-18 10:20:00

Why do broken characters appear when reading data through QTextStream?

Hello. When reading data from a QByteArray by a QTextStream object, some broken character gets into the result, while the rest of the text is normal.
My method code:

void DataChannel::queryDo()
{
    QByteArray bytes;
    bytes.clear();                                          // очистка буфера
    QDataStream out(&bytes, QIODevice::WriteOnly);
    out << this -> httpHeader;                              // QString

    QTextStream txt(&bytes, QIODevice::ReadOnly);
    QString t = txt.readAll();

    cout << this -> httpHeader.toStdString() << endl;
    cout << "===========================" << endl << endl;
    cout << t.toStdString() << endl;                        // проверка записанного текста
    this -> sock -> write(bytes);
}

In the this -> httpHeader line, the text is displayed normally. What could be the problem?
Program output: i.imgur.com/dfDigOK.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
viai, 2015-06-18
@lukinov93

Use the writeRawData() method to write to a QDataStream.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question