I have a Qt project that can load any HTML page into a web view. I have the following code in main.cpp
file:
#include "mainwindow.h"
#include <QApplication>
#include <QWebView>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWebView *view = new QWebView();
view->resize(400, 500);
view->load(QUrl("file:///absolute/path/to/my/html/file.html"));
view->show();
return app.exec();
}
This works fine, but I want to call a function from C++ side via Javascript loaded in file.html
(loaded in QWebView
).
So, having the following C++ function:
void sumOfNumbers (a, b)
{
qDebug() << a + b;
}
I want to call it from Javascript side:
someMethod("sumOfNumber", 12, 23);
that will print in the console 35
(12 + 23).
How can I do this?