与QWebEngineView组件交互
(通过loadFinished信号与titleChanged信号快速交互)

头文件
#include "QWebEngineView"

private:
Ui::MainWindow *ui;
QWebEngineView *view;

源文件

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);

//only a close button/
setWindowFlags(Qt::WindowCloseButtonHint);
setWindowModality(Qt::WindowModal);
init();
}
MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::init()
{
this->view = new QWebEngineView(this);
this->view->setContextMenuPolicy(Qt::NoContextMenu); //disable right click

QObject::connect(this->view,SIGNAL(titleChanged(QString)),this,SLOT(commSlot(QString)));
QObject::connect(this->view, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool)));

QString url = "qrc:/new/prefix1/ceclient.htm";
this->view->setUrl(QUrl(url));

}
void MainWindow::commSlot(QString str)
{
if (str.length() >1){
QString command=str.left(2);
QString json ="";
if (str.length()>2) json = str.mid(2);
// qDebug()< if (command =="~`") return;// null command
if (command =="e`")
{
this->close();
// QApplication::quit();
return;
}
if (command =="i`")
{
this->setGeometry(100,100,this->config["windows_width"].toInt(),this->config["windows_height"].toInt());
this->view->setGeometry(0,0,this->width(),this->height());
}
}
}

void MainWindow::slotLoadFinished(bool)
{
this->view->page()->runJavaScript("init();");

QDateTime today = QDateTime::currentDateTime();
QString ScriptComm +=" document.getElementById('list_date').value='"+today.toString("yyyy-MM-dd")+"';";
ScriptComm +=" document.getElementById('fromDate').value='"+today.toString("yyyy-MM-dd")+"';";
ScriptComm +=" document.getElementById('toDate').value='"+today.toString("yyyy-MM-dd")+"';";
ScriptComm +=" document.getElementById('assign_date').value='"+today.toString("yyyy-MM-dd")+"';";
this->view->page()->runJavaScript(ScriptComm);
}