Предупреждения при создании экземпляра объекта QWebChannel в javascript

У меня есть виджет, который создает экземпляр карт Google с помощью QWebChannel. При создании экземпляра QWebChannel в javascript появляется несколько предупреждений:

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-свойств, которые не имеют связанных сигналов, сигнализирующих об ошибке.

Учитывая вышеизложенное, есть 2 решения:

  • Чтобы отключить сообщение об ошибке, отключите qInstallMessageHandler:
QtCore.qInstallMessageHandler(lambda *args: None)
  • Не используйте self в качестве бэкэнда, а как QObject
class Backend(QObject):
    # getRef, getCenter, getPoints
self.backend = Backend(self)
self.webchannel.registerObject('backend', self.backend)
Другие вопросы по тегам