QTextCodec* defaultTextCodec = QTextCodec::codecForName("Windows-1251");QTextCodec::codecForHtml(_page.toLatin1().constData(), defaultTextCodec);QString page = htmlTextCodec->toUnicode(_page.toLatin1().constData());
QString page = QTextCodec::codecForName("Windows-1251")->toUnicode(_page.toLatin1());
QTextCodec* defaultTextCodec = QTextCodec::codecForName("Windows-1251"); QTextCodec* htmlTextCodec = QTextCodec::codecForHtml(_page.toLocal8Bit(), defaultTextCodec); QString page = htmlTextCodec->toUnicode(_page.toLocal8Bit());
QByteArray ba = pReply->readAll();QTextCodec* defaultTextCodec = QTextCodec::codecForName("Windows-1251");QString page = defaultTextCodec->toUnicode(ba);
QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba, QTextCodec *defaultCodec){ // determine charset QTextCodec *c = QTextCodec::codecForUtfText(ba, 0); if (!c) { QByteArray header = ba.left(1024).toLower(); int pos = header.indexOf("meta "); if (pos != -1) { pos = header.indexOf("charset=", pos); if (pos != -1) { pos += qstrlen("charset="); int pos2 = pos; // The attribute can be closed with either """, "'", ">" or "/", // none of which are valid charset characters. while (++pos2 < header.size()) { char ch = header.at(pos2); if (ch == '\"' || ch == '\'' || ch == '>') { QByteArray name = header.mid(pos, pos2 - pos); if (name == "unicode") // QTBUG-41998, ICU will return UTF-16. name = QByteArrayLiteral("UTF-8"); c = QTextCodec::codecForName(name); return c ? c : defaultCodec; } } } } } if (!c) c = defaultCodec; return c;}
QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba, QTextCodec *defaultCodec){ // determine charset int pos; QTextCodec *c = 0; c = QTextCodec::codecForUtfText(ba, c); if (!c) { QByteArray header = ba.left(512).toLower(); if ((pos = header.indexOf("http-equiv=")) != -1) { if ((pos = header.lastIndexOf("meta ", pos)) != -1) { pos = header.indexOf("charset=", pos) + int(strlen("charset=")); if (pos != -1) { int pos2 = header.indexOf('\"', pos+1); QByteArray cs = header.mid(pos, pos2-pos); // qDebug("found charset: %s", cs.data()); c = QTextCodec::codecForName(cs); } } } } if (!c) c = defaultCodec; return c;}