thnkwthprtls
thnkwthprtls

Reputation: 3487

Is there any way to use Qt and C++ to interact with a webpage?

I have a project using Qt 4.7. I need to display the contents of a webpage produced by performing a search on a website. The site has a box to type text into and an "ok" push button. When the ok button is pushed, it searches the site and goes to another page with the results. It's worth noting that these are NOT webpages made through Qt - they're just normal pages on a website. My Qt code so far is a simple UI with a QLineEdit and QPushButton. When the button is pushed, it needs to run the search on the site as if the user had typed the QLineEdit text into the search bar and clicked the ok button.

I know we're generally supposed to show sample code of what we've tried, but I honestly don't even know where to start with this, or if it's even possible. I've worked extensively with C++ but only a few months with Qt, and I've never had to write something like this. I've written code to write/parse HTML, but never to interact with a webpage that already exists. Can anyone please help? I'm really lost here. Thanks.

Edit: While looking for answers elsewhere online and seeing some of the similar-sounding questions people ask, I feel I should clarify: I absolutely am NOT in any way planning the use this for any sort of malware. It seems like a lot of similar questions get shot down over that, and I can assure everyone this project has no malicious intent whatsoever.

Upvotes: 0

Views: 628

Answers (1)

waddlesplash
waddlesplash

Reputation: 773

Try this:

   void on_nameOfPushButton_pressed()
   {
     nameOfWebView->load(QUrl(QString("http://<website-url>.com/<search-url>?q="+
                              QUrl::toPercentEncoding(nameOfLineEdit->text())); 
   }

Upvotes: 2

Related Questions