<i id='L0VXy'><tr id='L0VXy'><dt id='L0VXy'><q id='L0VXy'><span id='L0VXy'><b id='L0VXy'><form id='L0VXy'><ins id='L0VXy'></ins><ul id='L0VXy'></ul><sub id='L0VXy'></sub></form><legend id='L0VXy'></legend><bdo id='L0VXy'><pre id='L0VXy'><center id='L0VXy'></center></pre></bdo></b><th id='L0VXy'></th></span></q></dt></tr></i><div id='L0VXy'><tfoot id='L0VXy'></tfoot><dl id='L0VXy'><fieldset id='L0VXy'></fieldset></dl></div>

  • <tfoot id='L0VXy'></tfoot>
  • <legend id='L0VXy'><style id='L0VXy'><dir id='L0VXy'><q id='L0VXy'></q></dir></style></legend>

          <bdo id='L0VXy'></bdo><ul id='L0VXy'></ul>

      1. <small id='L0VXy'></small><noframes id='L0VXy'>

      2. 无法从 QML 中检索 PySide Signal 参数

        时间:2023-09-01

        • <bdo id='TQWyr'></bdo><ul id='TQWyr'></ul>
          <legend id='TQWyr'><style id='TQWyr'><dir id='TQWyr'><q id='TQWyr'></q></dir></style></legend>

                <tbody id='TQWyr'></tbody>

              1. <small id='TQWyr'></small><noframes id='TQWyr'>

                <tfoot id='TQWyr'></tfoot>

                  <i id='TQWyr'><tr id='TQWyr'><dt id='TQWyr'><q id='TQWyr'><span id='TQWyr'><b id='TQWyr'><form id='TQWyr'><ins id='TQWyr'></ins><ul id='TQWyr'></ul><sub id='TQWyr'></sub></form><legend id='TQWyr'></legend><bdo id='TQWyr'><pre id='TQWyr'><center id='TQWyr'></center></pre></bdo></b><th id='TQWyr'></th></span></q></dt></tr></i><div id='TQWyr'><tfoot id='TQWyr'></tfoot><dl id='TQWyr'><fieldset id='TQWyr'></fieldset></dl></div>
                  本文介绍了无法从 QML 中检索 PySide Signal 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我注意到 QML 可以使用 Connections 对象接收 Python 发出的信号.不幸的是,我不知道如何让该对象接收该信号的参数.

                  I've noticed that QML can receive a signal emitted from Python by using the Connections object. Unfortunately, I can't figure out how to get that object to receive the arguments of that signal.

                  我创建了一个最小的测试用例来演示我想要做什么:

                  I've created a minimal test case that demonstrates what I want to do:

                  min.py

                  from PySide import QtCore, QtGui, QtDeclarative
                  import sys
                  
                  # init Qt
                  app = QtGui.QApplication(sys.argv)
                  
                  # set up the signal
                  class Signaller(QtCore.QObject):
                      emitted = QtCore.Signal(str)
                  
                  signaller = Signaller()
                  
                  # Load the QML
                  qt_view = QtDeclarative.QDeclarativeView()
                  context = qt_view.rootContext()
                  context.setContextProperty('signaller', signaller)
                  qt_view.setResizeMode(QtDeclarative.QDeclarativeView.SizeRootObjectToView)
                  qt_view.setSource('min.qml')
                  qt_view.show()
                  
                  # launch the signal
                  signaller.emitted.emit("Please display THIS text!")
                  
                  # Run!
                  app.exec_()
                  

                  还有 min.qml

                  import QtQuick 1.0
                  
                  Rectangle {
                      width:300; height:100
                  
                      Text {
                          id: display
                          text: "No signal yet detected!"
                  
                          Connections {
                              target: signaller
                              onEmitted: {
                                  display.text = "???" //how to get the argument?
                              }
                          }
                      }
                  }
                  

                  推荐答案

                  从 Qt 4.8 开始,PySide 根本不处理信号参数名称.

                  As of Qt 4.8, PySide doesn't handle signal parameter names at all.

                  但是您可以使用命名参数创建一个 QML 信号并使用 Javascript 将您的 python 信号连接到它:

                  But you can create a QML signal with named parameters and connect your python signal to it using Javascript:

                  import QtQuick 1.0
                  
                  Rectangle {
                      width:300; height:100
                  
                  
                      Text {
                          id: display
                          text: "No signal yet detected!"
                  
                          signal reemitted(string text)
                          Component.onCompleted: signaller.emitted.connect(reemitted)
                  
                          onReemitted: {
                            display.text = text;        
                          }
                      }
                  }
                  

                  这篇关于无法从 QML 中检索 PySide Signal 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:QML Charts 导致启动时崩溃 下一篇:如何使 qml 对象的属性“动态更新"?通过套接字连接?

                  相关文章

                • <legend id='SLaRE'><style id='SLaRE'><dir id='SLaRE'><q id='SLaRE'></q></dir></style></legend>

                  <small id='SLaRE'></small><noframes id='SLaRE'>

                    <i id='SLaRE'><tr id='SLaRE'><dt id='SLaRE'><q id='SLaRE'><span id='SLaRE'><b id='SLaRE'><form id='SLaRE'><ins id='SLaRE'></ins><ul id='SLaRE'></ul><sub id='SLaRE'></sub></form><legend id='SLaRE'></legend><bdo id='SLaRE'><pre id='SLaRE'><center id='SLaRE'></center></pre></bdo></b><th id='SLaRE'></th></span></q></dt></tr></i><div id='SLaRE'><tfoot id='SLaRE'></tfoot><dl id='SLaRE'><fieldset id='SLaRE'></fieldset></dl></div>
                    <tfoot id='SLaRE'></tfoot>

                        <bdo id='SLaRE'></bdo><ul id='SLaRE'></ul>