我认为,如果您真正尝试某事并发布您的代码作为起点,那总是最好的。但是我工作很无聊,所以就这样吧......
这是一些伪代码:
// 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 文档示例
stackoverflow 有很多
}
}
}