新增miniblink示例
parent
850beb88f6
commit
aeb2d0c1eb
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
|
@ -45,6 +45,7 @@
|
|||
| 38 | designer | QtDesigner4源码 |
|
||||
| 39 | netserver | 网络中转服务器 |
|
||||
| 40 | mpvdemo | 视频流播放mpv内核 |
|
||||
| 41 | miniblink | miniblink示例 |
|
||||
|
||||
### 二、学习群
|
||||
1. **Qt交流大会群 853086607(雨田哥)**
|
||||
|
@ -93,3 +94,4 @@
|
|||
![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/live.png)
|
||||
![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/netserver.jpg)
|
||||
![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/designer.png)
|
||||
![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/0snap/miniblink.jpg)
|
|
@ -0,0 +1,18 @@
|
|||
<html>
|
||||
<head>
|
||||
<script>
|
||||
function onClicked() {
|
||||
//alert('hello');
|
||||
document.getElementById('label').innerHTML = '确实不错哦';
|
||||
objName_receiveData('type','data');
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Hello World</h1>
|
||||
<p>Hello World</p>
|
||||
<label id='label'>今天天气真棒</label>
|
||||
<input type="button" value="发送数据给Qt" onclick="onClicked()" />
|
||||
</body>
|
||||
</html>
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>ECharts</title>
|
||||
<script src="echarts.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main" style="height:500px;"></div>
|
||||
<script type="text/javascript">
|
||||
var myChart = echarts.init(document.getElementById('main'));
|
||||
function setGaugeValue(value){
|
||||
var option = {
|
||||
tooltip : {
|
||||
formatter: "{a} <br/>{b} : {c}%"
|
||||
},
|
||||
toolbox: {
|
||||
feature: {
|
||||
restore: {},
|
||||
saveAsImage: {}
|
||||
}
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '业务指标',
|
||||
type: 'gauge',
|
||||
detail: {formatter:'{value}%'},
|
||||
data: [{value: value, name: '完成率'}]
|
||||
}
|
||||
]
|
||||
};
|
||||
myChart.setOption(option);
|
||||
}
|
||||
window.onresize = myChart.resize;
|
||||
setGaugeValue(68);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,10 @@
|
|||
#include "widget.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
Widget w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
QT += core gui
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = miniblink
|
||||
TEMPLATE= app
|
||||
DESTDIR = $$PWD/../bin
|
||||
|
||||
CONFIG += warn_off
|
||||
HEADERS += widget.h
|
||||
SOURCES += main.cpp widget.cpp
|
||||
FORMS += widget.ui
|
||||
|
||||
INCLUDEPATH += $$PWD/miniblink
|
||||
include ($$PWD/miniblink/miniblink.pri)
|
|
@ -0,0 +1,107 @@
|
|||
#include "miniblink.h"
|
||||
#include "qapplication.h"
|
||||
#include "qdebug.h"
|
||||
|
||||
void onLoadingFinish(wkeWebView, void *param, const wkeString, wkeLoadingResult result, const wkeString)
|
||||
{
|
||||
//qDebug() << "onLoadingFinish" << result;
|
||||
//在注册函数的地方就已经传入了类指针
|
||||
miniblink *widget = (miniblink *)param;
|
||||
//0 = WKE_LOADING_SUCCEEDED, 1 = WKE_LOADING_FAILED, 2 = WKE_LOADING_CANCELED
|
||||
widget->loadFinish(result == 0);
|
||||
}
|
||||
|
||||
jsValue WKE_CALL_TYPE objName_receiveData(jsExecState es, void *param)
|
||||
{
|
||||
if (0 == jsArgCount(es)) {
|
||||
return jsUndefined();
|
||||
}
|
||||
|
||||
//挨个取出参数,设定的通用方法,只有两个参数
|
||||
jsValue arg0 = jsArg(es, 0);
|
||||
jsValue arg1 = jsArg(es, 1);
|
||||
if (!jsIsString(arg0)) {
|
||||
return jsUndefined();
|
||||
}
|
||||
|
||||
//在注册函数的地方就已经传入了类指针
|
||||
miniblink *widget = (miniblink *)param;
|
||||
QString type = QString::fromStdString(jsToString(es, arg0));
|
||||
QVariant data = QString::fromStdString(jsToString(es, arg1));
|
||||
widget->receiveData(type, data);
|
||||
return jsUndefined();
|
||||
}
|
||||
|
||||
miniblink::miniblink(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
//第一步先初始化动态库
|
||||
init();
|
||||
//第二步初始化浏览器控件
|
||||
//创建一个浏览器控件,放入句柄
|
||||
webView = wkeCreateWebWindow(WKE_WINDOW_TYPE_CONTROL, (HWND)this->winId(), 0, 0, this->width(), this->height());
|
||||
//关联完成信号
|
||||
wkeOnLoadingFinish(webView, onLoadingFinish, this);
|
||||
//设置浏览器控件可见
|
||||
wkeShowWindow(webView, TRUE);
|
||||
//注册通用的接收数据的方法,一定要放在这里在网页加载前执行
|
||||
wkeJsBindFunction("objName_receiveData", objName_receiveData, this, 2);
|
||||
}
|
||||
|
||||
void miniblink::init()
|
||||
{
|
||||
//全局只需要初始化一次
|
||||
static bool isInit = false;
|
||||
if (!isInit) {
|
||||
isInit = true;
|
||||
//不同的构建套件位数加载不同的动态库
|
||||
#ifdef Q_OS_WIN64
|
||||
QString file = qApp->applicationDirPath() + "/miniblink_64.dll";
|
||||
#else
|
||||
QString file = qApp->applicationDirPath() + "/miniblink.dll";
|
||||
#endif
|
||||
const wchar_t *path = reinterpret_cast<const wchar_t *>(file.utf16());
|
||||
wkeSetWkeDllPath(path);
|
||||
bool ok = wkeInitialize();
|
||||
qDebug() << QString("init miniblink %1").arg(ok ? "ok" : "error");
|
||||
}
|
||||
}
|
||||
|
||||
void miniblink::release()
|
||||
{
|
||||
wkeFinalize();
|
||||
}
|
||||
|
||||
void miniblink::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
wkeResize(webView, this->width(), this->height());
|
||||
}
|
||||
|
||||
void miniblink::loadFinish(bool ok)
|
||||
{
|
||||
emit loadFinished(ok);
|
||||
}
|
||||
|
||||
void miniblink::receiveData(const QString &type, const QVariant &data)
|
||||
{
|
||||
emit receiveDataFromJs(type, data);
|
||||
}
|
||||
|
||||
void miniblink::load(const QString &url, bool file)
|
||||
{
|
||||
const char *temp = url.toLocal8Bit().data();
|
||||
if (file) {
|
||||
wkeLoadFile(webView, temp);
|
||||
} else {
|
||||
wkeLoadURL(webView, temp);
|
||||
}
|
||||
}
|
||||
|
||||
void miniblink::setHtml(const QString &html, const QString &baseUrl)
|
||||
{
|
||||
wkeLoadHtmlWithBaseUrl(webView, html.toLocal8Bit().data(), baseUrl.toLocal8Bit().data());
|
||||
}
|
||||
|
||||
void miniblink::runJs(const QString &js)
|
||||
{
|
||||
wkeRunJS(webView, js.toLocal8Bit().data());
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef MINIBLINK_H
|
||||
#define MINIBLINK_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "wke.h"
|
||||
|
||||
class miniblink : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit miniblink(QWidget *parent = 0);
|
||||
|
||||
//初始化资源
|
||||
static void init();
|
||||
//释放资源
|
||||
static void release();
|
||||
|
||||
protected:
|
||||
//设置浏览器控件自动适应大小
|
||||
void resizeEvent(QResizeEvent *);
|
||||
|
||||
private:
|
||||
//浏览器控件对象
|
||||
wkeWebView webView;
|
||||
|
||||
signals:
|
||||
//网页载入完成
|
||||
void loadFinished(bool ok);
|
||||
//收到网页发出来的数据
|
||||
void receiveDataFromJs(const QString &type, const QVariant &data);
|
||||
|
||||
public:
|
||||
//给回调用的函数
|
||||
void loadFinish(bool ok);
|
||||
void receiveData(const QString &type, const QVariant &data);
|
||||
|
||||
public slots:
|
||||
//加载网址或者本地文件
|
||||
void load(const QString &url, bool file = false);
|
||||
//加载html内容
|
||||
void setHtml(const QString &html, const QString &baseUrl);
|
||||
//执行js函数
|
||||
void runJs(const QString &js);
|
||||
};
|
||||
|
||||
#endif // MINIBLINK_H
|
|
@ -0,0 +1,3 @@
|
|||
HEADERS += $$PWD/wke.h
|
||||
HEADERS += $$PWD/miniblink.h
|
||||
SOURCES += $$PWD/miniblink.cpp
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,12 @@
|
|||
### 特别说明
|
||||
1. 编译后记得将file目录和对应dll目录下的所有文件拷贝到可执行文件同一目录。
|
||||
2. 动态库地址:[https://pan.baidu.com/s/13LDRu6mXC6gaADtrGprNVA](https://pan.baidu.com/s/13LDRu6mXC6gaADtrGprNVA) 提取码: ujm7
|
||||
3. 收费增强版:[https://qtchina.blog.csdn.net/article/details/104005917](https://qtchina.blog.csdn.net/article/details/104005917)
|
||||
4. miniblink只支持windows。
|
||||
|
||||
### 其他说明
|
||||
1. 作品大全:[https://qtchina.blog.csdn.net/article/details/97565652](https://qtchina.blog.csdn.net/article/details/97565652)
|
||||
2. 国内站点:[https://gitee.com/feiyangqingyun](https://gitee.com/feiyangqingyun)
|
||||
3. 国际站点:[https://github.com/feiyangqingyun](https://github.com/feiyangqingyun)
|
||||
4. 个人主页:[https://blog.csdn.net/feiyangqingyun](https://blog.csdn.net/feiyangqingyun)
|
||||
5. 知乎主页:[https://www.zhihu.com/people/feiyangqingyun/](https://www.zhihu.com/people/feiyangqingyun/)
|
|
@ -0,0 +1,65 @@
|
|||
#include "widget.h"
|
||||
#include "ui_widget.h"
|
||||
#include "qapplication.h"
|
||||
#include "qdebug.h"
|
||||
|
||||
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->initForm();
|
||||
on_btnLoadFile_clicked();
|
||||
}
|
||||
|
||||
Widget::~Widget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void Widget::initForm()
|
||||
{
|
||||
webView = new miniblink;
|
||||
connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
|
||||
connect(webView, SIGNAL(receiveDataFromJs(QString, QVariant)),
|
||||
this, SLOT(receiveDataFromJs(QString, QVariant)));
|
||||
ui->gridLayout->addWidget(webView, 0, 0);
|
||||
}
|
||||
|
||||
void Widget::loadFinished(bool ok)
|
||||
{
|
||||
qDebug() << "加载完成" << ok;
|
||||
}
|
||||
|
||||
void Widget::receiveDataFromJs(const QString &type, const QVariant &data)
|
||||
{
|
||||
qDebug() << "收到数据" << type << data;
|
||||
}
|
||||
|
||||
void Widget::on_btnLoadUrl_clicked()
|
||||
{
|
||||
webView->load("https://www.baidu.com");
|
||||
}
|
||||
|
||||
void Widget::on_btnLoadFile_clicked()
|
||||
{
|
||||
webView->load(qApp->applicationDirPath() + "/demo.html", true);
|
||||
}
|
||||
|
||||
void Widget::on_btnLoadHtml_clicked()
|
||||
{
|
||||
QStringList html;
|
||||
html << "<html><body>";
|
||||
html << "<h2>Hello World</h2>";
|
||||
html << "</body></html>";
|
||||
webView->setHtml(html.join(""), "");
|
||||
}
|
||||
|
||||
void Widget::on_btnRunJs_clicked()
|
||||
{
|
||||
webView->load(qApp->applicationDirPath() + "/gauge.html", true);
|
||||
}
|
||||
|
||||
void Widget::on_horizontalSlider_valueChanged(int value)
|
||||
{
|
||||
QString js = QString("setGaugeValue(%1)").arg(value);
|
||||
webView->runJs(js);
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef WIDGET_H
|
||||
#define WIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "miniblink.h"
|
||||
|
||||
namespace Ui {
|
||||
class Widget;
|
||||
}
|
||||
|
||||
class Widget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Widget(QWidget *parent = 0);
|
||||
~Widget();
|
||||
|
||||
private:
|
||||
Ui::Widget *ui;
|
||||
miniblink *webView;
|
||||
|
||||
private slots:
|
||||
void initForm();
|
||||
//网页载入完成
|
||||
void loadFinished(bool ok);
|
||||
//收到网页发出来的数据
|
||||
void receiveDataFromJs(const QString &type, const QVariant &data);
|
||||
|
||||
private slots:
|
||||
void on_btnLoadUrl_clicked();
|
||||
void on_btnLoadFile_clicked();
|
||||
void on_btnLoadHtml_clicked();
|
||||
void on_btnRunJs_clicked();
|
||||
void on_horizontalSlider_valueChanged(int value);
|
||||
};
|
||||
|
||||
#endif // WIDGET_H
|
|
@ -0,0 +1,91 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Widget</class>
|
||||
<widget class="QWidget" name="Widget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>miniblink使用示例</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>3</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnLoadUrl">
|
||||
<property name="text">
|
||||
<string>加载网页</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnLoadFile">
|
||||
<property name="text">
|
||||
<string>加载文件</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnLoadHtml">
|
||||
<property name="text">
|
||||
<string>加载内容</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnRunJs">
|
||||
<property name="text">
|
||||
<string>执行JS</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="horizontalSlider">
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>68</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -1,9 +1,9 @@
|
|||
编译完成以后记得将dll文件复制到可执行文件同一目录。
|
||||
|
||||
对应各个版本的dll文件下载地址:https://pan.baidu.com/s/13LDRu6mXC6gaADtrGprNVA 提取码: ujm7
|
||||
|
||||
收费增强版本:[https://qtchina.blog.csdn.net/article/details/107972067](https://qtchina.blog.csdn.net/article/details/107972067)
|
||||
### 特别说明
|
||||
1. 编译完成以后记得将dll文件复制到可执行文件同一目录。
|
||||
2. 动态库地址:[https://pan.baidu.com/s/13LDRu6mXC6gaADtrGprNVA](https://pan.baidu.com/s/13LDRu6mXC6gaADtrGprNVA) 提取码: ujm7
|
||||
3. 收费增强版:[https://qtchina.blog.csdn.net/article/details/107972067](https://qtchina.blog.csdn.net/article/details/107972067)
|
||||
|
||||
### 其他说明
|
||||
1. 作品大全:[https://qtchina.blog.csdn.net/article/details/97565652](https://qtchina.blog.csdn.net/article/details/97565652)
|
||||
2. 国内站点:[https://gitee.com/feiyangqingyun](https://gitee.com/feiyangqingyun)
|
||||
3. 国际站点:[https://github.com/feiyangqingyun](https://github.com/feiyangqingyun)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
编译完成以后记得将dll文件复制到可执行文件同一目录。
|
||||
|
||||
对应各个版本的dll文件下载地址:https://pan.baidu.com/s/13LDRu6mXC6gaADtrGprNVA 提取码: ujm7
|
||||
|
||||
收费增强版本:[https://qtchina.blog.csdn.net/article/details/103946067](https://qtchina.blog.csdn.net/article/details/103946067)
|
||||
### 特别说明
|
||||
1. 编译完成以后记得将dll文件复制到可执行文件同一目录。
|
||||
2. 动态库地址:[https://pan.baidu.com/s/13LDRu6mXC6gaADtrGprNVA](https://pan.baidu.com/s/13LDRu6mXC6gaADtrGprNVA) 提取码: ujm7
|
||||
3. 收费增强版:[https://qtchina.blog.csdn.net/article/details/103946067](https://qtchina.blog.csdn.net/article/details/103946067)
|
||||
|
||||
### 其他说明
|
||||
1. 作品大全:[https://qtchina.blog.csdn.net/article/details/97565652](https://qtchina.blog.csdn.net/article/details/97565652)
|
||||
2. 国内站点:[https://gitee.com/feiyangqingyun](https://gitee.com/feiyangqingyun)
|
||||
3. 国际站点:[https://github.com/feiyangqingyun](https://github.com/feiyangqingyun)
|
||||
|
|
Loading…
Reference in New Issue