在 javascript 中实例化 QWebChannel 对象时的警告
Posted
技术标签:
【中文标题】在 javascript 中实例化 QWebChannel 对象时的警告【英文标题】:Warnings when instantiating QWebChannel object in javascript 【发布时间】:2019-11-18 01:31:42 【问题描述】:我有一个使用 QWebChannel 创建谷歌地图实例的小部件。在 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))
【问题讨论】:
【参考方案1】:QWebChannel 将分析已注册对象的 q 属性,以验证它们是否具有关联的信号。在您的警告消息的情况下,我推断“self”是一个 QWidget,因此它有许多 q-properties,没有相关联的信号表明错误。
鉴于上述情况,有两种解决方案:
通过禁用 qInstallMessageHandler 来消除错误消息:QtCore.qInstallMessageHandler(lambda *args: None)
不要使用“self”作为后端,而是使用 QObject
class Backend(QObject):
# getRef, getCenter, getPoints
self.backend = Backend(self)
self.webchannel.registerObject('backend', self.backend)
【讨论】:
以上是关于在 javascript 中实例化 QWebChannel 对象时的警告的主要内容,如果未能解决你的问题,请参考以下文章