#include "mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , m_mainView(new QWidget(this))
    , m_mainLayout(new QVBoxLayout(m_mainView))
    , m_webView(new QWebEngineView())
    , m_btn(new QPushButton("C++调用js代码"))
{
    initUI();
    initConnect();
}

MainWindow::~MainWindow()
{

}

void MainWindow::initUI()
{
    connect(m_btn,&QPushButton::clicked,this,&MainWindow::soltClickBtn);
}

void MainWindow::initConnect()
{
    m_webView->load(QUrl("qrc:/web/index.html"));
    m_mainLayout->addWidget(m_webView);
    m_mainLayout->addWidget(m_btn);
    m_mainView->setLayout(m_mainLayout);
    setCentralWidget(m_mainView);
}

void MainWindow::soltClickBtn()
{
    qWarning()<<"soltClickBtn";
    m_webView->page()->runJavaScript("cl()");
}
