我認爲它總是最好的,如果你真正嘗試的東西,並張貼您的代碼作爲一個起點。但我在工作無聊所以這裏去....
下面是一些僞代碼雜交:
// To request data from the interwebs.
QNetworkRequest* request = new QNetworkRequest("http://www.asdf.com");
QNetworkAccessManager* networkMgr = new QNetworkAccessManager();
QNetworkReply* reply = networkMgr->get(request);
// Set up signals & slots (Qt4 style)
QObject::connect(reply, SIGNAL(readyRead()), this, SLOT(readyRead()));
QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error(QNetworkReply::NetworkError)));
以後,當你得到你的有效載荷,可以讀取數據,並將其送入什麼Qt的XML解析器你想(QXmlStreamReader和其他人!):
void HttpTest::readyRead()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
if(reply)
{
if(reply->error() == QNetworkReply::NoError)
{
}
else
{
QString html = reply->readAll();
QXmlStreamReader reader(&html);
// Parse your xml stuff - search for your <p> node.
// ...
Qt doc examples
stackoverflow has lots
}
}
}
來源
2013-07-12 18:44:41
Huy
http://qt-project.org/doc/qt-4.8/examples-xml.html – Huy
http://stackoverflow.com/questions/12913881/parse-a-xml-file-using-c- qt – Huy
這是針對XML的,我是否需要下載網頁並運行正則表達式,plz help – David