上传项目代码

This commit is contained in:
lixiaoyuan
2025-05-19 09:54:33 +08:00
commit 4a198a7271
589 changed files with 993786 additions and 0 deletions

41
src/widgets/WidgetWeb.cpp Normal file
View File

@@ -0,0 +1,41 @@
#include "WidgetWeb.h"
WebHandler::WebHandler(QObject* parent)
: QObject {parent}
{
webChannel = new QWebChannel();
// 注册C++对象到QWebChannel这样远端的QWebChannel也会生成一个对应的JS对象
// 在JS中引入 qwebchannel.js 使用 channel.objects.webNative 获取注册的“webNative”
webChannel->registerObject("webNative", this);
}
void WebHandler::setNativeText(const QString& text)
{
m_nativeText = text;
qDebug() << QString("setNativeText:") << text;
emit signalNativeTextChanged(text);
}
WidgetWeb::WidgetWeb(QWidget* parent) : QWebEngineView(parent)
{
webHandler_ = new WebHandler();
this->page()->setWebChannel(webHandler_->webChannel);
this->setContextMenuPolicy(Qt::NoContextMenu);
}
void WidgetWeb::loadHtml(std::string url)
{
// "file:///assets/html/echarts//maptest.html"
this->load(QUrl(url.c_str()));
connect(this, &QWebEngineView::loadFinished, this, &WidgetWeb::slotLoadFinished);
}
void WidgetWeb::invikeJS(QString jscode)
{
//QString jscode = QString("showalert('%1')").arg("Hello QtWebEngine!");
this->page()->runJavaScript(jscode, [](const QVariant& v) { qDebug() << v.toString(); });
}
void WidgetWeb::slotLoadFinished(bool ret)
{
}