You can go the other way - all the actions that need to be done with the page are performed using JavaScript, and in C ++ only process the result. I will explain.
Imagine that you have a QWebEngineView
QWebEngineView *view;
You can assign a callback function to the page load event.
connect(view, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool)));
Call up landing page
view->load(QUrl(requestUrl));
When loading will be executed, for simplification of work with JavaScript, we will add jQuery. JQuery - the string obtained from the resource file. After adding jQuery, add your javascript code and result handler. The finishLoading function might look like this.
void MyClass::finishLoading(bool) { view->page()->runJavaScript(JQuery::Instance()->Code()); view->page()->runJavaScript(YOUR_JS_CODE, invoke(this, &MyClass::onResultCallback)); }
Where, YOUR_JS_CODE is a QString with page processing code. for example
const QString YOUR_JS_CODE = " \ function doSomething(){ \ var results = $('.content'); \ if (results != 'undefined') \ return results.html(); \ return ''; \ }; doSomething();";
Please note that you need to call the added code (last line).
Finally, you need to process the result.
void MyClass::onResultCallback(const QVariant& returnValue) { QString result = ""; bool isOk = false; result = returnValue.toString(&isOk); if (!isOk) { // Обработка ошибки return; } // Логика работы с результатом. }
For reference, I recommend to watch fancybrowser or querychecker based on it.