Under qt, I post a query to server using QTcpSocket.
I will receive an xml result.
I use QLabel to display xml content.
I have tried like this.
QDataStream ini(&sock);
QString result;
in >> result;
ui->label->setText(result);
I’m sorry that I cant provide result, because stackoverflow don’t allow me post images.
But I got some messy code instead of xml. What’s the reason?
Sometimes I can receive some http response words though very rare.
And I will appreciate if you can tell me how to do it.
Perhaps it’s how I display xml content made messy code. I’m confused.:)
1) The data from the server is not in datastream format. So you cannot read it using QDatastream. Use sock->read()/sock->readAll() directly instead.
2) Make sure you use the QLabel in plain text mode:
Using a QTextBrowser (also, with setPlainText) would be more useful though and will give you more readable and easier to navigate output.