#pragma once

#include <QWebChannel>
#include <QtWebEngineWidgets/QWebEngineView>
#include <string>

class WebHandler : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString nativeText READ nativeText MEMBER m_nativeText NOTIFY signalNativeTextChanged FINAL)

public:
    explicit WebHandler(QObject* parent = nullptr);

    QString nativeText() const { return m_nativeText; }

signals:
    //在C++中定义的信号，可以在JS端监听此信号接收消息
    void signalNativeTextChanged(const QString& text);

public slots:
    //C++ 端的公共槽函数，可以在JS端调用。
    void setNativeText(const QString& text);

public:
    QString m_nativeText;
    QWebChannel* webChannel;
};


class WidgetWeb : public QWebEngineView
{
public:
    WidgetWeb(QWidget* parent);

    void loadHtml(std::string url);

    void invikeJS(QString jscode);

    // slots
    void slotLoadFinished(bool ret);



public:
    WebHandler* webHandler_;

};