3

I am trying to display a web page using C++/QT with dynamic data.

  1. If user clicks, the web page should be displayed
  2. The web page should contains a table format data. The data will be read from the table using C++ and will be dynamic.

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

0

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.

2 Comments

I need to display a web with dynamic data. I will get the data at run time which need to be displayed on the web page in a table format.
Can you elaborate on what you mean by dynamic data in this situation?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.