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

标签 python pyqt pyqt5 qtwebengine qtwebchannel

我有一个使用 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))

最佳答案

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

鉴于上述情况,有 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)

关于python - 在 javascript 中实例化 QWebChannel 对象时的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58906917/

相关文章:

python - PyQt4 到 PyQt5 -> mainFrame() 已弃用,需要修复才能加载网页

python - Pandas - 按大小总和对 Multiindex 进行排序

python - 在 Python 中限制函数执行

python - 在pyqt中禁用窗口功能

python - 如何将 Python 捆绑到 macos .app 应用程序中?

python - 如何使 QTreeWidget 中的特定列成为整数/ float ,以便用户无法输入任何字母或符号而不是整数/ float ?

python - 解压一个 numpy ndarray 的元组并将其添加到一个新的维度

python - spaCy 实际上实现了哪些神经网络模型?什么决定了它们在内存中的大小?

python - Pipenv无法安装PyQt5

python - 我可以将 Paraview 的渲染器或交互器添加到我的 PyQt5 应用程序中吗?