Here is my solution if anyone is interested. I had problem adding the js directly in the html so I used injection
QWebEngineProfile *profile = new QWebEngineProfile("MyWebChannelProfile", this);
// QWebEngineProfile *profile = qApp->property("WebEngineProfile").value<QWebEngineProfile*>();
QFile webChannelJsFile(":/qtwebchannel/qwebchannel.js");
if( !webChannelJsFile.open(QIODevice::ReadOnly) ) {
qDebug() << QString("Couldn't open qwebchannel.js file: %1").arg(webChannelJsFile.errorString());
}
else {
qDebug() << "OK webEngineProfile";
QByteArray webChannelJs = webChannelJsFile.readAll();
webChannelJs.append(
"\n"
"var workoutCreator"
"\n"
"new QWebChannel(qt.webChannelTransport, function(channel) {"
" workoutCreator = channel.objects.workoutCreator;"
"});"
"\n"
"function enableSaveButton() {"
"var nameValue = $('#name-workout').val();"
"var planValue = $('#plan-workout').val();"
"var creatorValue = $('#creator-workout').val();"
"if (nameValue.length > 0 && creatorValue.length > 0 && planValue.length > 0) {$('#btn-save-workout').prop('disabled', false);}"
"else {$('#btn-save-workout').prop('disabled', true);}"
"}"
);
QWebEngineScript script;
script.setSourceCode(webChannelJs);
script.setName("qwebchannel.js");
script.setWorldId(QWebEngineScript::MainWorld);
script.setInjectionPoint(QWebEngineScript::DocumentCreation);
script.setRunsOnSubFrames(false);
profile->scripts()->insert(script);
}
QWebEnginePage *myPage = new QWebEnginePage(profile, ui->webView_createWorkout);
ui->webView_createWorkout->setPage(myPage);
QWebChannel *channel = new QWebChannel(myPage);
ui->webView_createWorkout->page()->setWebChannel(channel);
channel->registerObject("workoutCreator", this);
}
void WorkoutCreator::checkToEnableButtonSave() {
if (intervalModel->rowCount() <= 0) {
return;
}
//call JS to activate button!
ui->webView_createWorkout->page()->runJavaScript("enableSaveButton();");
}