Reputation: 11
I am trying to find a way to connect a button in HTML to an action in my C++/Qt application. I loaded a HTML file in QT app using QTextBrowser object. If I click a button in this HTML file, the Qt application should respond. I also might want to implement it vice versa: so that an action in the Qt application would cause a response in the HTML page. Please suggest a suitable solution.
My sample code is :
QWebView view;
view.setStyleSheet(
"background-color:rgb(150,147,88); padding: 7px ; color:rgb(255,255,255)");
view.load(QUrl("test.html"));
view.show();
is there any mechanism like signal/slot ??
Upvotes: 1
Views: 2469
Reputation: 8147
There are a few ways to do this, as your sample is working with QWebView rather than QTextBrowser, I'll assume your working with the QWebView.
For page to application QWebView::linkClicked(const QUrl& url)
signal is fired when a link is clicked, and QWebView::load(const QUrl& url)
will change the page.
If you are creating a JavaScript application, have a look at the QtWebKit Bridge documentation. This allows two way communication with JavaScript running on a page.
Upvotes: 5