Reputation: 1451
I am trying to display a web page using C++/QT with dynamic data.
Upvotes: 3
Views: 2983
Reputation: 150
You can set the HTML content of QWebView using setHtml()
function. Have a look at the documentation. Call it when the user clicks the button to load HTML.
To get the contents of loaded HTML code you can use two methods provided by QWebFrame inside your QWebView:
webview->page()->mainFrame()->toPlainText()
webview->page()->mainFrame()->toHTML()
You will have to parse the HTML to read data from table shown in QWebView.
Upvotes: 3
Reputation: 1
Have a look at QWebView, http://doc.qt.io/qt-5/qwebview.html
Example from the website above
QWebView *view = new QWebView(parent);
view->load(QUrl("http://qt.nokia.com/"));
view->show();
Create this view in the event handler from where the User clicks and all should work fine.
Upvotes: 0
Reputation: 2007
Answer to First Question
You can use QWebView to display your start-up html using QWebView::setHtml()
or QWebView::load()
function.
Answer to Second Question
Regarding this question, there can be multiple ways in which you can set dynamic data in your page.
One way is you can use javascript function to update your html table. Which you will insert in the html in <script>
tag. Now you can pass data (read through c++) using following function..
webView->page()->mainFrame()->evaluateJavaScript(yourJavascript);
Well you will have to generate javascript function call string yourJavascript
from the data read through c++.
But if you can retrieve your data from database in JSON format, it will be very easy for you. For example you can use QJson third party library to parse and serialize JSON data as per following..
QByteArray data; // Say data arrived from the database is stored in this object.
QJson::Parser parser;
QVariantMap map = parser.parse(data).toMap();
// Now serialize it and pass it to javascript function as an argument..
QJson::Serializer serializer;
QString javaScript = "updateHtmlView(" + serializer.serialize(map) + ");";
webView->page()->mainFrame()->evaluateJavaScript(javaScript);
So now you can update your html table by reading that JSON object in javascript.
Upvotes: 2