bon finalement j’ai trouvé comment faire, voici le code minimal :
webengine_test.pro :
QT += core gui webenginewidgets webchannel
mainwindow.h :
public slots:
void sendMessage(QString message) ;
mainwindow.cpp :
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->webview->load(QUrl("file://"+QDir::currentPath()+"/index.html"));
QWebChannel * channel = new QWebChannel(ui->webview->page());
ui->webview->page()->setWebChannel(channel);
channel->registerObject(QString("widget"), this);
}
void MainWindow::sendMessage(QString message)
{
QMessageBox msgBox;
msgBox.setText(message);
msgBox.exec();
}
index.html :
<script type="text/javascript" src="qwebchannel.js"></script>
<script>
window.onload = function() {
new QWebChannel(qt.webChannelTransport, function(channel) {
var foo = channel.objects.widget;
foo.sendMessage("message bien reçu!");
});
}
</script>
qwebchannel.js