Search code examples
qtqwebkitqwebpageqwebelement

all webcontent to string


First of all, I don't even know how to begin, QtWebKit is the first time i need in qt.

What I'm after is to realt a contant of webpage https://bla.com/something.php the webpage will contain only one word, so no worries about the content and this content i need to store in QString variable in order to futher work with that.

Can you please help me make a function to return this QString?

I found that QWebPage::SelectAll somehow can do it, but honestly I don't know what to #include in the header of my main.cpp file and what to QT += and then how to write this function...

I bealive its would be pretty easy for someone who knows what to do...

PS:I don't want to open the browser in the process, just need to extract the string as fast, quick, clean as possible.

EDIT: the webcontent is php based and will store no html tags, only plain text. The full content of the php file will be something like this:

<?php
    function test() {
        return "test";
    }
  echo test();
?>

Solution

  • at the end, it was pretty simple:

    QNetworkAccessManager manager;
    QNetworkReply *response;
    QEventLoop event;
    response = manager.get(QNetworkRequest(QUrl("www.someurl.com/something")));
    connect(response, SIGNAL(finished()), &event, SLOT(quit()));
    event.exec();
    QString result = response->readAll(); // now result holds the entire content of webpage