Manage Web Content without QWebChannel
-
Can I manipulate a web page without using QWebChannel? Just in case it's possible, and how am I going to do that?
For example, how can c++ detect if a button from a web page was clicked?
-
Can I manipulate a web page without using QWebChannel? Just in case it's possible, and how am I going to do that?
For example, how can c++ detect if a button from a web page was clicked?
@LovelyGrace
Not with QtWebEngine.
With QtWebkit (removed since Qt 5.6) its possible, but you will have to build the module yourself. -
Even if I use QWebEnginePage::runJavaScript()? Though I tried but it's not working. So in other words we manage the javascript on the web without qwebchannel?
And what do you mean to build my own module?
-
Even if I use QWebEnginePage::runJavaScript()? Though I tried but it's not working. So in other words we manage the javascript on the web without qwebchannel?
And what do you mean to build my own module?
@LovelyGrace said in Manage Web Content without QWebChannel:
Even if I use QWebEnginePage::runJavaScript()?
you can manipulate the DOM, but you won't be able to make a dynamic connection (or notification upon changes) back to C++.
And what do you mean to build my own module?
As i said QtWebkit isn't part of Qt releases post 5.6.
But it is still available (and more or less unmaintained) in the repositories: http://code.qt.io/cgit/qt/qtwebkit.git/ -
By manipulating the DOM, can i get the data from the web page? like for example, on the login page, when user clicked the login, the c++ can detect the username of the users using QWebEnginePage::run JavaScript()?
QWebEnginePage *page = new QWebEnginePage;
page = view.page();
page->runJavaScript(QString("document.getElementById('username').value"), [](const QVariant& res) {
qDebug() << "Username = " << res.toString();
});Ive tried the codes above but i get this error: [0129/141308:INFO:CONSOLE(1)] "Uncaught TypeError: Cannot read property 'value' of null", source: (1)
Username = ""
js: Uncaught TypeError: Cannot read property 'click' of null
[0129/141308:INFO:CONSOLE(1)] "Uncaught TypeError: Cannot read property 'click' of null", source: (1)
js: The key "" is not recognized and ignored. -
By manipulating the DOM, can i get the data from the web page? like for example, on the login page, when user clicked the login, the c++ can detect the username of the users using QWebEnginePage::run JavaScript()?
QWebEnginePage *page = new QWebEnginePage;
page = view.page();
page->runJavaScript(QString("document.getElementById('username').value"), [](const QVariant& res) {
qDebug() << "Username = " << res.toString();
});Ive tried the codes above but i get this error: [0129/141308:INFO:CONSOLE(1)] "Uncaught TypeError: Cannot read property 'value' of null", source: (1)
Username = ""
js: Uncaught TypeError: Cannot read property 'click' of null
[0129/141308:INFO:CONSOLE(1)] "Uncaught TypeError: Cannot read property 'click' of null", source: (1)
js: The key "" is not recognized and ignored.@LovelyGrace
looks like there is no element with an id ofusername
Probably you are executing your code too early (before the page has been loaded)? -
how am I going to fix it?
-
yes i think it was executed before the page was finished loading.