How can I use Qt to get html code of the redirected page??

Posted by Claire Huang on Stack Overflow See other posts from Stack Overflow or by Claire Huang
Published on 2010-04-03T23:08:23Z Indexed on 2010/04/04 0:43 UTC
Read the original article Hit count: 489

Filed under:
|
|

I'm trying to use Qt to download the html code from the following url:

http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=nucleotide&cmd=search&term=AB100362

this url will re-direct to

www.ncbi.nlm.nih.gov/nuccore/27884304

I try to do it by following way, but I cannot get anything. it works for some webpage such as www.google.com, but not for this NCBI page. is there any way to get this page??

QNetworkReply::NetworkError downloadURL(const QUrl &url, QByteArray &data)
{
    QNetworkAccessManager manager;
    QNetworkRequest request(url);
    QNetworkReply *reply = manager.get(request);

    QEventLoop loop;
    QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    loop.exec();

    if (reply->error() != QNetworkReply::NoError)
    {
        return reply->error();
    }
    data = reply->readAll();
    delete reply;
    return QNetworkReply::NoError;
}

void GetGi()
{
        int pos;

        QString sGetFromURL = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi";
        QUrl url(sGetFromURL);
        url.addQueryItem("db", "nucleotide");
        url.addQueryItem("cmd", "search");
        url.addQueryItem("term", "AB100362");

        QByteArray InfoNCBI;
        int errorCode = downloadURL(url, InfoNCBI);
        if (errorCode != 0 )
        {
            QMessageBox::about(0,tr("Internet Error "), tr("Internet Error %1: Failed to connect to NCBI.\t\nPlease check your internect connection.").arg(errorCode));
            return "ERROR";
        }

}

© Stack Overflow or respective owner

Related posts about qt4

Related posts about c++