JasonGenX
JasonGenX

Reputation: 5434

Severe limitation for QWebView

I have a table inside HTML I am submitting to a QWebView.

The table grows during the lifecycle of the application.

If I manage the html QString on the side and just "setHtml" with every update I run into a performance problem where adding 1000 rows to the table takes minutes.

Isn't there a way for me to access the HTML directly on the QWebView and inject the new table row every time, updating the html directly?

Upvotes: 1

Views: 875

Answers (1)

jdi
jdi

Reputation: 92569

I believe what you want is to interact with the QWebFrame, which is the lowest level object. You can access it via: QWebView->page()->mainFrame()

From the QWebFrame, you could either use evaluateJavaScript() to simply send snippets to the page for execution.

Or you can register a QObject with the frame using addToJavaScriptWindowObject, that bridges between your Qt code and the javascript page. You can read more in detail here. But this approach would let the javascript-side define a function as a "slot" and connect to a signal defined on your QObject, such as updateTable(). Then whenever you do something on the Qt side and emit the data with that signal, the javascript will catch it and handle it.

Qt

 QWebFrame *frame = myWebPage->mainFrame();
 frame->addToJavaScriptWindowObject("tableHandler", tableHandlerObject);

Javscript

 function handleTableUpdate() { ... }
 ...
 tableHandler.updateReady.connect(handleTableUpdate);

Upvotes: 1

Related Questions