在javascript中实例化QWebChannel对象时的警告

问题描述 投票:0回答:1

我有一个小部件,可使用QWebChannel创建一个Google地图实例。当在javascript中实例化QWebChannel时,出现几个警告:

Property 'accessibleName'' of object 'MapWindow' has no notify signal and is not constant, value updates in HTML will be broken!
Property 'accessibleDescription'' of object 'MapWindow' has no notify signal and is not constant, value updates in HTML will be broken!
Property 'layoutDirection'' of object 'MapWindow' has no notify signal and is not constant, value updates in HTML will be broken!
Property 'autoFillBackground'' of object 'MapWindow' has no notify signal and is not constant, value updates in HTML will be broken!
Property 'styleSheet'' of object 'MapWindow' has no notify signal and is not constant, value updates in HTML will be broken!
Property 'locale'' of object 'MapWindow' has no notify signal and is not constant, value updates in HTML will be broken!
Property 'windowFilePath'' of object 'MapWindow' has no notify signal and is not constant, value updates in HTML will be broken!
Property 'inputMethodHints'' of object 'MapWindow' has no notify signal and is not constant, value updates in HTML will be broken!
var backend = null;
new QWebChannel(qt.webChannelTransport, function(channel) {
    backend = channel.objects.backend;
    backend.getRef(function(ref) {
        backend.getCenter(function(center) {
            backend.getPoints(function(points){
                map = new google.maps.Map(document.getElementById('map'), {
                   center: center[0],
                   zoom: 10
                 });
                 ...
self.mapView = QWebEngineView()
self.webchannel = QWebChannel(self.mapView)
self.mapView.page().setWebChannel(self.webchannel)
self.webchannel.registerObject('backend', self)
current_dir = os.path.dirname(os.path.realpath(__file__))
filename = os.path.join(current_dir, '.\Resources\index.html')
self.mapView.load(QUrl.fromLocalFile(filename))
python pyqt pyqt5
1个回答
0
投票

QWebChannel将分析已注册对象的q属性,以验证它们具有关联的信号。在警告消息的情况下,我推断“ self”是QWidget,因此它具有许多q属性,没有相关的信号指示错误。

鉴于以上提供了两种解决方案:

  • 通过禁用qInstallMessageHandler使错误消息静音:
QtCore.qInstallMessageHandler(lambda *args: None)
  • [请勿将“ self”用作后端,而应使用QObject
class Backend(QObject):
    # getRef, getCenter, getPoints
self.backend = Backend(self)
self.webchannel.registerObject('backend', self.backend)
© www.soinside.com 2019 - 2024. All rights reserved.