Here is HttpServer in JAVA, that sends russian string to Qt application:
public void handle(HttpExchange t) throws IOException {
//Response from server in Russian
String response = "Ответ от сервера на русском языке"; //"Response from server in Russian"
t.sendResponseHeaders(200, response.length());
OutputStream os = t.getResponseBody();
//os.write(response.getBytes());
//right now I am trying this code
os.write(response.getBytes(Charset.forName("UTF-8"))); //and UTF-16
//also I have tried this
os.write(Charset.forName("UTF-16").encode(response).array());
os.close();
}
Application in Qt gets response from server (text in russian)
void MainWindow::Response(QNetworkReply *reply) {
QByteArray data = reply->readAll();
// Also I've tried this
// QString dataString = (QString)reply->readAll();
// QString dataLine = (QString)reply->readLine();
// QString str= QString::fromUtf8(data);
qDebug() << "data from server: " << data;
label->setText(str);
}
I just want to show normal string in console or in label component, but I have empty string or array of bytes or sequence of question marks
"\xCE\xF2\xE2\xE5\xF2 \xEE\xF2 \xF1\xE5\xF0\xE2\xE5\xF0\xE0 \xED\xE0 \xF0\xF3\xF1\xF1\xEA\xEE\xEC \xFF\xE7\xFB\xEA\xE5"
How can I solve this problem with encoding and convert this array to QString and finally see the normal text ?