jite672
jite672

Reputation: 23

How to get a web page source code using QT Creator?

I'm using Qt Creator and C++ and need to assign a web page source code to a text variable. But not sure if I should use QWebEngineView, QTextBrowser or other class, and specially what function.

QString sourcecode=someFunction(www.example.com);

Upvotes: 0

Views: 201

Answers (1)

kib
kib

Reputation: 61

You can include QtNetwork and try something like the following, where url_string is your http address as std::string :

    QNetworkAccessManager manager;
    QUrl url(url_string.c_str());
    QNetworkRequest request(url);
    QNetworkReply *reply(manager.get(request));
    QEventLoop loop;
    QObject::connect(reply, SIGNAL(finished()) , &loop, SLOT(quit()));
    loop.exec();

    std::string ret = reply->readAll().toStdString();

Upvotes: 1

Related Questions