1. 程式人生 > >PyQt裡QWebEngineView內嵌網頁與Python的資料互動

PyQt裡QWebEngineView內嵌網頁與Python的資料互動

資料互動需要load進一個網頁,這裡我選擇load進一個本地html網頁:JSTest.html。

同時,QWebEngineView與外面的互動還需要Qt官方提供的一個js檔案:qwebchannel.js,這個檔案可以在網上下載。

JSTest.html和qwebchannel.js兩個檔案放在同一個目錄下,我這邊都是放在Python工程目錄下。

qwebchannel.js:

/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of The Qt Company Ltd nor the names of its
**     contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/

"use strict";

var QWebChannelMessageTypes = {
    signal: 1,
    propertyUpdate: 2,
    init: 3,
    idle: 4,
    debug: 5,
    invokeMethod: 6,
    connectToSignal: 7,
    disconnectFromSignal: 8,
    setProperty: 9,
    response: 10,
};

var QWebChannel = function(transport, initCallback)
{
    if (typeof transport !== "object" || typeof transport.send !== "function") {
        console.error("The QWebChannel expects a transport object with a send function and onmessage callback property." +
                      " Given is: transport: " + typeof(transport) + ", transport.send: " + typeof(transport.send));
        return;
    }

    var channel = this;
    this.transport = transport;

    this.send = function(data)
    {
        if (typeof(data) !== "string") {
            data = JSON.stringify(data);
        }
        channel.transport.send(data);
    }

    this.transport.onmessage = function(message)
    {
        var data = message.data;
        if (typeof data === "string") {
            data = JSON.parse(data);
        }
        switch (data.type) {
            case QWebChannelMessageTypes.signal:
                channel.handleSignal(data);
                break;
            case QWebChannelMessageTypes.response:
                channel.handleResponse(data);
                break;
            case QWebChannelMessageTypes.propertyUpdate:
                channel.handlePropertyUpdate(data);
                break;
            default:
                console.error("invalid message received:", message.data);
                break;
        }
    }

    this.execCallbacks = {};
    this.execId = 0;
    this.exec = function(data, callback)
    {
        if (!callback) {
            // if no callback is given, send directly
            channel.send(data);
            return;
        }
        if (channel.execId === Number.MAX_VALUE) {
            // wrap
            channel.execId = Number.MIN_VALUE;
        }
        if (data.hasOwnProperty("id")) {
            console.error("Cannot exec message with property id: " + JSON.stringify(data));
            return;
        }
        data.id = channel.execId++;
        channel.execCallbacks[data.id] = callback;
        channel.send(data);
    };

    this.objects = {};

    this.handleSignal = function(message)
    {
        var object = channel.objects[message.object];
        if (object) {
            object.signalEmitted(message.signal, message.args);
        } else {
            console.warn("Unhandled signal: " + message.object + "::" + message.signal);
        }
    }

    this.handleResponse = function(message)
    {
        if (!message.hasOwnProperty("id")) {
            console.error("Invalid response message received: ", JSON.stringify(message));
            return;
        }
        channel.execCallbacks[message.id](message.data);
        delete channel.execCallbacks[message.id];
    }

    this.handlePropertyUpdate = function(message)
    {
        for (var i in message.data) {
            var data = message.data[i];
            var object = channel.objects[data.object];
            if (object) {
                object.propertyUpdate(data.signals, data.properties);
            } else {
                console.warn("Unhandled property update: " + data.object + "::" + data.signal);
            }
        }
        channel.exec({type: QWebChannelMessageTypes.idle});
    }

    this.debug = function(message)
    {
        channel.send({type: QWebChannelMessageTypes.debug, data: message});
    };

    channel.exec({type: QWebChannelMessageTypes.init}, function(data) {
        for (var objectName in data) {
            var object = new QObject(objectName, data[objectName], channel);
        }
        // now unwrap properties, which might reference other registered objects
        for (var objectName in channel.objects) {
            channel.objects[objectName].unwrapProperties();
        }
        if (initCallback) {
            initCallback(channel);
        }
        channel.exec({type: QWebChannelMessageTypes.idle});
    });
};

function QObject(name, data, webChannel)
{
    this.__id__ = name;
    webChannel.objects[name] = this;

    // List of callbacks that get invoked upon signal emission
    this.__objectSignals__ = {};

    // Cache of all properties, updated when a notify signal is emitted
    this.__propertyCache__ = {};

    var object = this;

    // ----------------------------------------------------------------------

    this.unwrapQObject = function(response)
    {
        if (response instanceof Array) {
            // support list of objects
            var ret = new Array(response.length);
            for (var i = 0; i < response.length; ++i) {
                ret[i] = object.unwrapQObject(response[i]);
            }
            return ret;
        }
        if (!response
            || !response["__QObject*__"]
            || response.id === undefined) {
            return response;
        }

        var objectId = response.id;
        if (webChannel.objects[objectId])
            return webChannel.objects[objectId];

        if (!response.data) {
            console.error("Cannot unwrap unknown QObject " + objectId + " without data.");
            return;
        }

        var qObject = new QObject( objectId, response.data, webChannel );
        qObject.destroyed.connect(function() {
            if (webChannel.objects[objectId] === qObject) {
                delete webChannel.objects[objectId];
                // reset the now deleted QObject to an empty {} object
                // just assigning {} though would not have the desired effect, but the
                // below also ensures all external references will see the empty map
                // NOTE: this detour is necessary to workaround QTBUG-40021
                var propertyNames = [];
                for (var propertyName in qObject) {
                    propertyNames.push(propertyName);
                }
                for (var idx in propertyNames) {
                    delete qObject[propertyNames[idx]];
                }
            }
        });
        // here we are already initialized, and thus must directly unwrap the properties
        qObject.unwrapProperties();
        return qObject;
    }

    this.unwrapProperties = function()
    {
        for (var propertyIdx in object.__propertyCache__) {
            object.__propertyCache__[propertyIdx] = object.unwrapQObject(object.__propertyCache__[propertyIdx]);
        }
    }

    function addSignal(signalData, isPropertyNotifySignal)
    {
        var signalName = signalData[0];
        var signalIndex = signalData[1];
        object[signalName] = {
            connect: function(callback) {
                if (typeof(callback) !== "function") {
                    console.error("Bad callback given to connect to signal " + signalName);
                    return;
                }

                object.__objectSignals__[signalIndex] = object.__objectSignals__[signalIndex] || [];
                object.__objectSignals__[signalIndex].push(callback);

                if (!isPropertyNotifySignal && signalName !== "destroyed") {
                    // only required for "pure" signals, handled separately for properties in propertyUpdate
                    // also note that we always get notified about the destroyed signal
                    webChannel.exec({
                        type: QWebChannelMessageTypes.connectToSignal,
                        object: object.__id__,
                        signal: signalIndex
                    });
                }
            },
            disconnect: function(callback) {
                if (typeof(callback) !== "function") {
                    console.error("Bad callback given to disconnect from signal " + signalName);
                    return;
                }
                object.__objectSignals__[signalIndex] = object.__objectSignals__[signalIndex] || [];
                var idx = object.__objectSignals__[signalIndex].indexOf(callback);
                if (idx === -1) {
                    console.error("Cannot find connection of signal " + signalName + " to " + callback.name);
                    return;
                }
                object.__objectSignals__[signalIndex].splice(idx, 1);
                if (!isPropertyNotifySignal && object.__objectSignals__[signalIndex].length === 0) {
                    // only required for "pure" signals, handled separately for properties in propertyUpdate
                    webChannel.exec({
                        type: QWebChannelMessageTypes.disconnectFromSignal,
                        object: object.__id__,
                        signal: signalIndex
                    });
                }
            }
        };
    }

    /**
     * Invokes all callbacks for the given signalname. Also works for property notify callbacks.
     */
    function invokeSignalCallbacks(signalName, signalArgs)
    {
        var connections = object.__objectSignals__[signalName];
        if (connections) {
            connections.forEach(function(callback) {
                callback.apply(callback, signalArgs);
            });
        }
    }

    this.propertyUpdate = function(signals, propertyMap)
    {
        // update property cache
        for (var propertyIndex in propertyMap) {
            var propertyValue = propertyMap[propertyIndex];
            object.__propertyCache__[propertyIndex] = propertyValue;
        }

        for (var signalName in signals) {
            // Invoke all callbacks, as signalEmitted() does not. This ensures the
            // property cache is updated before the callbacks are invoked.
            invokeSignalCallbacks(signalName, signals[signalName]);
        }
    }

    this.signalEmitted = function(signalName, signalArgs)
    {
        invokeSignalCallbacks(signalName, signalArgs);
    }

    function addMethod(methodData)
    {
        var methodName = methodData[0];
        var methodIdx = methodData[1];
        object[methodName] = function() {
            var args = [];
            var callback;
            for (var i = 0; i < arguments.length; ++i) {
                if (typeof arguments[i] === "function")
                    callback = arguments[i];
                else
                    args.push(arguments[i]);
            }

            webChannel.exec({
                "type": QWebChannelMessageTypes.invokeMethod,
                "object": object.__id__,
                "method": methodIdx,
                "args": args
            }, function(response) {
                if (response !== undefined) {
                    var result = object.unwrapQObject(response);
                    if (callback) {
                        (callback)(result);
                    }
                }
            });
        };
    }

    function bindGetterSetter(propertyInfo)
    {
        var propertyIndex = propertyInfo[0];
        var propertyName = propertyInfo[1];
        var notifySignalData = propertyInfo[2];
        // initialize property cache with current value
        // NOTE: if this is an object, it is not directly unwrapped as it might
        // reference other QObject that we do not know yet
        object.__propertyCache__[propertyIndex] = propertyInfo[3];

        if (notifySignalData) {
            if (notifySignalData[0] === 1) {
                // signal name is optimized away, reconstruct the actual name
                notifySignalData[0] = propertyName + "Changed";
            }
            addSignal(notifySignalData, true);
        }

        Object.defineProperty(object, propertyName, {
            configurable: true,
            get: function () {
                var propertyValue = object.__propertyCache__[propertyIndex];
                if (propertyValue === undefined) {
                    // This shouldn't happen
                    console.warn("Undefined value in property cache for property \"" + propertyName + "\" in object " + object.__id__);
                }

                return propertyValue;
            },
            set: function(value) {
                if (value === undefined) {
                    console.warn("Property setter for " + propertyName + " called with undefined value!");
                    return;
                }
                object.__propertyCache__[propertyIndex] = value;
                webChannel.exec({
                    "type": QWebChannelMessageTypes.setProperty,
                    "object": object.__id__,
                    "property": propertyIndex,
                    "value": value
                });
            }
        });

    }

    // ----------------------------------------------------------------------

    data.methods.forEach(addMethod);

    data.properties.forEach(bindGetterSetter);

    data.signals.forEach(function(signal) { addSignal(signal, false); });

    for (var name in data.enums) {
        object[name] = data.enums[name];
    }
}

//required for use with nodejs
if (typeof module === 'object') {
    module.exports = {
        QWebChannel: QWebChannel
    };
}

JSTest.html:

<!DOCTYPE html>  
<html>  
    <head>  
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
        <script type="text/javascript" src="./qwebchannel.js"></script>  
        <script type="text/javascript">  
        //---Web show receive message---
        function output(message)  
        {  
            var output = document.getElementById("output");  
            output.innerHTML = output.innerHTML + message + "\n";  
        }  
		function showAlert() 
		{
			alert('this is web alert');
        }
        
        //Web initial loading 
         window.onload = function() 
		 {
            new QWebChannel(qt.webChannelTransport, function(channel) 
			{
                //Get Qt interact object  
                var interactObj = channel.objects.interactObj; 
                
                //Web send message to Qt 
                document.getElementById("send").onclick = function() 
				{
                    var input = document.getElementById("input");
                    if (!input.value) 
					{  
                        return;  
                    }  
					output("Send string to Qt: " + input.value);  
                    
                    //Web use the interface of Qt 
					interactObj.fun(alert);
                    interactObj.JSSendMessage(input.value);  
                    input.value = "";                      
                }  
                
                //Web connect the Qt signal, then Qt can call "output" function
                interactObj.SigSendMessageToJS.connect(function(str) 
				{  
                    output("Received string from Qt: " + str);  
                });    
            });  
        }  
  
        </script>  
        <style type="text/css">  
            html {  
                height: 100%;  
                width: 100%;  
            }  
            #input {  
                width: 650px;  
                margin: 0 10px 0 0;  
            }  
            #send {  
                width: 90px;  
                margin: 0;  
            }  
            #output {  
                width: 770px;  
                height: 550px;  
            }  
        </style>  
    </head>  
    <body>  
        <textarea id="output" readonly="readonly"></textarea><br />  
        <input id="input" />  
        <input type="submit" id="send" value="Send" onclick="javascript:click();" />  
    </body>  
</html>

接下來是Python工程裡的程式碼。

main.py:

from PyQt5.QtWidgets import QApplication
import sys
from TMainWindow import TMainWindow

if __name__ == '__main__':
    app = QApplication(sys.argv)

    dlg = TMainWindow()
    dlg.show()

    app.exec_()

TMainWindow.py:

from PyQt5.QtWidgets import QDialog, QPlainTextEdit, QLineEdit, QPushButton, QHBoxLayout, QVBoxLayout
from PyQt5.QtWidgets import QGroupBox
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWebChannel import *
from PyQt5.QtCore import QUrl, pyqtSignal
from TInteractObject import TInteractObj

class TMainWindow(QDialog):
    SigSendMessageToJS = pyqtSignal(str)
    def __init__(self, parent = None):
        super().__init__(parent)
        #---Qt widget and layout---
        self.mpQtContentTextEdit = QPlainTextEdit(self)
        self.mpQtContentTextEdit.setMidLineWidth(400)
        self.mpQtContentTextEdit.setReadOnly(True)

        self.mpQtSendLineEdit = QLineEdit(self)

        self.mpQtSendBtnByInteractObj = QPushButton('Send', self)
        self.mpQtSendBtnByInteractObj.setToolTip('Send message by Interact object style')

        self.mpQtSendBtnByJavaScript = QPushButton('Send2', self)
        self.mpQtSendBtnByJavaScript.setToolTip('Send message by runJavaScript style')

        self.pQtSendHLayout = QHBoxLayout()
        self.pQtSendHLayout.setSpacing(0)
        self.pQtSendHLayout.addWidget(self.mpQtSendLineEdit)
        self.pQtSendHLayout.addSpacing(5)
        self.pQtSendHLayout.addWidget(self.mpQtSendBtnByInteractObj)
        self.pQtSendHLayout.addSpacing(5)
        self.pQtSendHLayout.addWidget(self.mpQtSendBtnByJavaScript)

        self.pQtTotalVLayout = QVBoxLayout()
        self.pQtTotalVLayout.setSpacing(0)
        self.pQtTotalVLayout.addWidget(self.mpQtContentTextEdit)
        self.pQtTotalVLayout.setSpacing(5)
        self.pQtTotalVLayout.addLayout(self.pQtSendHLayout)

        self.pQtGroup = QGroupBox('Qt View', self)
        self.pQtGroup.setLayout(self.pQtTotalVLayout)

        #---Web widget and layout---
        self.mpJSWebView = QWebEngineView(self)
        self.pWebChannel = QWebChannel(self.mpJSWebView.page())
        self.pInteractObj = TInteractObj(self)
        self.pWebChannel.registerObject("interactObj", self.pInteractObj)

        self.mpJSWebView.page().setWebChannel(self.pWebChannel)

        self.url = 'file:///D:/PyPro/PyQtJSInteract/JSTest.html'
        self.mpJSWebView.page().load(QUrl(self.url))
        self.mpJSWebView.show()

        self.pJSTotalVLayout = QVBoxLayout()
        self.pJSTotalVLayout.setSpacing(0)
        self.pJSTotalVLayout.addWidget(self.mpJSWebView)
        self.pWebGroup = QGroupBox('Web View', self)
        self.pWebGroup.setLayout(self.pJSTotalVLayout)

        #---TMainWindow total layout---
        self.mainLayout = QHBoxLayout()
        self.mainLayout.setSpacing(0)
        self.mainLayout.addWidget(self.pQtGroup)
        self.mainLayout.setSpacing(5)
        self.mainLayout.addWidget(self.pWebGroup)
        self.setLayout(self.mainLayout)
        self.setMinimumSize(1130, 680)

        self.mpQtSendBtnByInteractObj.clicked.connect(self.OnSendMessageByInteractObj)
        self.mpQtSendBtnByJavaScript.clicked.connect(self.OnSendMessageByJavaScript)
        self.pInteractObj.SigReceivedMessFromJS.connect(self.OnReceiveMessageFromJS)
        self.SigSendMessageToJS.connect(self.pInteractObj.SigSendMessageToJS)

    def OnReceiveMessageFromJS(self, strParameter):
        print('OnReceiveMessageFromJS()')
        if not strParameter:
            return
        self.mpQtContentTextEdit.appendPlainText(strParameter)

    def OnSendMessageByInteractObj(self):
        strMessage = self.mpQtSendLineEdit.text()
        if not strMessage:
            return
        self.SigSendMessageToJS.emit(strMessage)

    def OnSendMessageByJavaScript(self):
        strMessage = self.mpQtSendLineEdit.text()
        if not strMessage:
            return
        strMessage = 'Received string from Qt:' + strMessage
        self.mpJSWebView.page().runJavaScript("output(%s)" %strMessage)
        self.mpJSWebView.page().runJavaScript("showAlert()")

建構函式前半部分為控制元件及佈局。

倒數第二行的runJavaScript函式沒執行成功,沒能成功傳引數給JS那邊,這個後續再跟進。不過在OnSendMessageByInteractObj(self)函式裡能成功傳引數給JS那邊,這裡用的是QWebChannel。而JS傳引數給Python則用的是OnReceiveMessageFromJS(self, strParameter)函式。

TInteractObject.py:

from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot

class TInteractObj(QObject):
    SigReceivedMessFromJS = pyqtSignal(str)
    SigSendMessageToJS = pyqtSignal(str)
    def __init__(self, parent = None):
        super().__init__(parent)

    @pyqtSlot(str)
    def JSSendMessage(self, strParameter):
        print('JSSendMessage(%s) from Html' %strParameter)
        self.SigReceivedMessFromJS.emit(strParameter)

    @pyqtSlot(result=str)
    def fun(self):
        print('TInteractObj.fun()')
        return 'hello'
JS呼叫Python的函式必須是槽函式,否則Python這邊沒有響應,會給人一種沒有收到的錯覺。在C++裡槽函式是public slots,而Python裡則用@pyqtSlot來定義,後面括號內為引數型別。如果該槽函式有返回值,則在括號內加上“result=引數型別”。

執行後效果如下圖:


之前有關PyQt QWebEngineView的資料比較少,搞了好久,現在終於搞好了。整理了後寫了出來,希望對有需要的人有所幫助。

相關推薦

PyQtQWebEngineView網頁Python資料互動

資料互動需要load進一個網頁,這裡我選擇load進一個本地html網頁:JSTest.html。同時,QWebEngineView與外面的互動還需要Qt官方提供的一個js檔案:qwebchannel.js,這個檔案可以在網上下載。JSTest.html和qwebchanne

微信小程式網頁互動實現支付功能

上個月,小程式開放了新功能,支援內嵌網頁,所以我就開始了小程式內嵌網頁之路,之前我只是個小安卓。 內嵌網頁中可使用JSSDK 1.3.0提供的介面,可坑就來了,居然不支援支付介面的呼叫,經過一番研究,總算打通了兩邊的互動。 大概流程 1、先說明涉及到的檔案,下面會

測試了小程序的網頁總結幾點

百度首頁 寶貝 百度 業務 iframe 淘寶 一個 頁面 寶寶   11月2日深夜微信團隊宣布小程序內嵌頁面開放了,很多開發者已經測試了小程序的內嵌網頁,他們總結了以下幾點: 1、內嵌網頁的域名需要在小程序管理後臺設置為業務域名,也就是需要先加入白名單 一個小程序最多可

[小程序開發] 微信小程序網頁web-view開發教程

工具 內容 不支持 clas .html bind har 開發 style 為了便於開發者靈活配置小程序,微信小程序開放了內嵌網頁能力。這意味著小程序的內容不再局限於pages和large,我們可以借助內嵌網頁豐富小程序的內容。下面附上詳細的開發教程(含視頻操作以及註意事

Unity 網頁

內嵌 androi tail 使用 post lin int bsp tails uniwebview 官網 http://uniwebview.onevcat.com/ Unity中內嵌網頁插件 UniWebView 2.8使用 http://gad.qq.com/art

WPF應用程序網頁

決定 程序 har dev Language 需要 eve -name cati 原文:WPF應用程序內嵌網頁 版權聲明:本文為博主原創文章,轉載請註明出處。 https://blog.csdn.net/shaynerain/arti

小程式網頁能力開放

為便於開發者靈活配置小程式,現開放小程式內嵌網頁能力。 web-view 元件是一個可以用來承載網頁的容器,會自動鋪滿整個小程式頁面。 個人型別與海外型別的小程式暫不支援使用。 使用方式: <!-- wxml --><!-- 指向微信公眾平臺首頁的web-view -->&l

iframe網頁踩坑合集

iOS的iframe寬度bug iOS下的safari是按照iframe裡面頁面元素的全尺寸來調整iframe的大小的。 輪播效果的實現原理是將所有的幻燈片都放到一個塊裡面,然後設定溢位隱藏,在iOS的iframe下,結合上面第一條原因,就會將iframe撐得很大。 在ifram

淺談小程式網頁網頁跳轉分享實現

上個月,小程式開發內嵌web頁面的功能,這個對於很多微信開發者都是個重大訊息。最近兩天,筆者專案中有這樣一個需求,支援小程式內嵌網頁,並且在內嵌網頁中多次跳轉,分享後,點開還是在跳轉之後的網頁。對於這樣一個新技術,還是充滿好奇,既然老大說了要做,那就嘗試去做唄。 首先

使用iframe網頁的時候,如何做到網頁的高度自適應

在頁面無重新整理更新方面,雖然現在的ajax很強悍,但是處理程式碼相對多點。想比之下,iframe就簡單多了!處理iframe的自適應寬、高,會經常用到,網上整理了一份,寫在這裡備用: 單個iframe 高度自適應: <iframe id="iFrame1" nam

WPF應用程式網頁

WPF內嵌網頁,可以將網頁本地化,經查詢相關資料後,決定採用CefSharp 1、首先新建WPF工程,開啟工具進入NUGET,搜尋CefSharp,然後安裝CefSharp.Wpf 2、完成後,將專案改為x64或者x86,然後新增引用,這裡有兩種方法分開來說,大同小異 3、

Unity中網頁外掛UniWebView使用總結

一、目前有三種方式可以實現在Unity工程中實現內嵌網頁的功能: 1、  UnityWebCore:只支援Windows平臺,呼叫瀏覽器核心,將網頁渲染到mesh,作為gameObject。 2、  Unity-Webview:只適用於Andriod和ios平臺,呼叫

關於 jsp網頁內容

1)include指令include指令告訴容器:複製被包含檔案彙總的所有內容,再把它貼上到這個檔案中。 <%@ include file="Header.jsp"%> (2)include標準動作 <jsp:include page=“Header.jsp”/> (3)採用JST

關於Unity程式在IOS和Android上顯示網頁的方式

最近由於有需要在Unity程式執行在ios或android手機上顯示內嵌網頁。所以遍從網上搜集了一下相關的資料。整理如下: UnityWebCore 從搜尋中先看到了這個,下載下來了以後發現這個的原理好像是通過呼叫瀏覽器核心,然後將網頁渲染到mesh的方式完成的。但遺憾

sql語句使用檢視臨時表示例

某些時候,查詢需要將資料與其他一些可能只能通過執行 GROUP BY 然後執行標準查詢才能收集的資料進行聯接。例如,如果要查詢最新五個定單的有關資訊,您首先需要知道是哪些定單。這可以使用返回定單 ID 的 SQL 查詢來檢索。此資料就會儲存在臨時表(這是一個常用技術)中,然後

mysqlpython互動 pymysql

mysql與python的互動 pymysql 主鍵寫0,null,default都自動遞增 不是主鍵,預設,只能寫default 1.拆為多個表 先建立一個新的表 if not exists 如果原來不存在就建立表 寫入:insert into good_cates (na

Mongodb的使用方法&python互動

一、Mongodb的介紹和安裝 1. nosql的介紹 “NoSQL”⼀詞最早於1998年被⽤於⼀個輕量級的關係資料庫的名字 隨著web2.0的快速發展, NoSQL概念在2009年被提了出來 NoSQL在2010年⻛⽣⽔起, 現在國內外眾多⼤⼩⽹站, 如fa

在AxWebBrowser控制元件裡面讓網頁客戶端互動(wcf或ComVisible)

1 使用Wcf暴露服務 [ServiceContract] public interface IOperateSevice { /// <summary> /// 儲存資訊到InsuranceClient主程式 ///

MongoDB的聚合操作以及Python互動

MongoDB聚合 什麼是聚合 MongoDB中聚合(aggregate)主要用於處理資料(諸如統計平均值,求和等),並返回計算後的資料結果。 聚合是基於資料處理的聚合管道,每個文件通過由多個階段組成的管道,可以對每個階段的管道進行分組、過濾等功能,然後經過一系列處理,輸出結果。 語法:db.集合名稱

MongoDB 安裝詳細教程 + 常用命令 + Python互動

MongoDB 簡介 MongoDB (名稱來自 humongous/巨大無比的, 是一個可擴充套件的高效能,開源,模式自由,面向文件的NoSQL,基於 分散式 檔案儲存,由 C++ 語言編寫,設計之初旨在為 WEB 應用提供可擴充套件的高效能資料儲存解決方案。 MongoDB使用的是記憶體對映儲存引