Hi there,
I am running QHtml to get a Website with German chars.
For some reason they are not encoded (e.g. ä), but come raw ('ä').
After getting it, I want to to run it through HTML tidy (to make it valid XML) and then parse it and search for text, but the German chars are not processed correctly.
main.cpp:
Code:
#include <QtCore/QCoreApplication> #include <QProcess> #include <QBuffer> #include <QDomDocument> #include <iostream> #include "synchttp.h" #include <QFile> using namespace std; int main(int argc, char **argv ) { QBuffer buffer; SyncHTTP http("back2hack.cc"); http.syncGet("/", &buffer); ar.replace("ä", "ae"); QProcess process; QStringList arguments; arguments << "-q" << "-asxml"; process.start("./tidy", arguments ); process.waitForStarted(); process.write(ar); process.waitForBytesWritten(); process.closeWriteChannel(); process.waitForFinished(); //std::cout << array.data(); QDomDocument doc; QString error; int row, column; doc.setContent(array, false, &error, &row, &column ); std::cout << error.toLatin1().data(); //std::cout << doc.firstChild().toText().data().toLatin1().data(); QString text; QList<QDomNode> l; while(!c.isNull()) { while(!c.isNull()) { if(c.toElement().text() == "Blogsystem: Einträge absteigend sortieren" ) l.append(c); c = c.nextSibling(); } n = n.firstChild(); } cout << qPrintable(n.toElement().text()); cout << qPrintable(n.toElement().tagName()); cout << l.length(); } file.write(buffer.data()); return 0; }
synchttp.h:
Code:
/*************************************************************************** * Copyright (C) 2005 by Iulian M * * eti@erata.net * ***************************************************************************/ #ifndef ETKSYNCHTTP_H #define ETKSYNCHTTP_H #include <QHttp> #include <QEventLoop> #include <QBuffer> /** * Provide a synchronous api over QHttp * Uses a QEventLoop to block until the request is completed * @author Iulian M <eti@erata.net> */ { Q_OBJECT public: /// structors virtual ~SyncHTTP(){} /// send GET request and wait until finished { ///connect the requestFinished signal to our finished slot connect(this,SIGNAL(requestFinished(int,bool)),SLOT(finished(int,bool))); /// start the request and store the requestID requestID = get(path, to ); /// block until the request is finished loop.exec(); /// return the request status return status; } /// send POST request and wait until finished { ///connect the requestFinished signal to our finished slot connect(this,SIGNAL(requestFinished(int,bool)),SLOT(finished(int,bool))); /// start the request and store the requestID requestID = post(path, data , to ); /// block until the request is finished loop.exec(); /// return the request status return status; } { /// create io device from QByteArray QBuffer buffer; buffer.setData(data); return syncPost(path,&buffer,to); } protected slots: virtual void finished(int idx, bool err) { /// check to see if it's the request we made if(idx!=requestID) return; /// set status of the request status = !err; /// end the loop loop.exit(); } private: /// id of current request int requestID; /// error status of current request bool status; /// event loop used to block until request finished QEventLoop loop; }; #endif
What could be the reason?
