在javascrip中实例化QWebChannel对象时出现警告

2024-09-25 00:36:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个小部件,它使用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))

Tags: andofnoinsignalobjectisvalue
1条回答
网友
1楼 · 发布于 2024-09-25 00:36:38

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)

相关问题 更多 >