runJavaScript is to run your own javascript i think..
not script from other ...
i load Qt5::Script to test but i see javascript alert().
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} Qt5::WebEngineWidgets)
target_link_libraries(${PROJECT_NAME} Qt5::Script)
#include <QApplication>
#include <QWebEngineView>
#include <iostream>
using namespace std;
class Webkit: public QWebEngineView{
public:
Webkit() {
connect(this->page(), &QWebEnginePage::loadFinished, this, &Webkit::onFinishedLoading);
}
public slots:
void onFinishedLoading(bool ok);
};
void Webkit::onFinishedLoading(bool ok){
this
->page
()->runJavaScript
("document.body;alert(\"I am an alert box!\")",
[](const QVariant &v
) { cout <<
"JS Result:" << v.
toString().
toStdString() << endl;
});
}
int main(int argc, char *argv[])
{
Webkit kit;
kit.show();
kit.
setUrl(QUrl("https://wiki.selfhtml.org/wiki/JavaScript/Objekte/Date/getFullYear"));
return app.exec();
}
#include <QApplication>
#include <QWebEngineView>
#include <iostream>
using namespace std;
class Webkit: public QWebEngineView{
public:
Webkit() {
connect(this->page(), &QWebEnginePage::loadFinished, this, &Webkit::onFinishedLoading);
}
public slots:
void onFinishedLoading(bool ok);
};
void Webkit::onFinishedLoading(bool ok){
this->page()->runJavaScript("document.body;alert(\"I am an alert box!\")", [](const QVariant &v) { cout << "JS Result:" << v.toString().toStdString() << endl; });
}
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
Webkit kit;
kit.show();
kit.setUrl(QUrl("https://wiki.selfhtml.org/wiki/JavaScript/Objekte/Date/getFullYear"));
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks