PySide2 QAction 事件被阻止,直到 window 关闭

PySide2 QAction Event Blocked until window closed

运行 遇到事件循环似乎被阻止的问题(或者我没有启动事件循环?)而且我无法追查它。

GUI 出现,菜单有响应,但是单击文件->打开,应该 创建一个近乎立即的打印语句并没有发生.

我知道我已将正确的信号映射到插槽,因为只要您执行“文件”->“退出”或关闭 window,就会出现打印语句。

我用相同的 UI 文件在 C++ 中实现了这个相同的示例,它按预期工作。

问题出现在以下配置中:

test.ui:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>200</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Qt for Python</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QGridLayout" name="gridLayout"/>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>940</width>
     <height>21</height>
    </rect>
   </property>
   <widget class="QMenu" name="menuFile">
    <property name="title">
     <string>File</string>
    </property>
    <addaction name="actionOpen"/>
    <addaction name="actionQuit"/>
   </widget>
   <addaction name="menuFile"/>
  </widget>
  <action name="actionQuit">
   <property name="text">
    <string>Quit</string>
   </property>
  </action>
  <action name="actionOpen">
   <property name="text">
    <string>Open</string>
   </property>
  </action>
 </widget>
 <resources/>
 <connections>
  <connection>
   <sender>actionQuit</sender>
   <signal>triggered()</signal>
   <receiver>MainWindow</receiver>
   <slot>close()</slot>
  </connection>
 </connections>
</ui>

test.py:

#!/usr/bin/env python
import sys

from PySide2 import QtCore, QtGui, QtWidgets

from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import QApplication
from PySide2.QtCore import QFile


class MyWidget(QtCore.QObject):
    def __init__(self):
        QtCore.QObject.__init__(self)

        file = QFile("test.ui")
        file.open(QFile.ReadOnly)

        loader = QUiLoader()
        self.ui = loader.load(file)

        openAction = self.ui.findChild(QtWidgets.QAction, 'actionOpen')
        openAction.triggered.connect(self.func)

    @QtCore.Slot()
    def func(self):
        print("func has been called!")

app = QtWidgets.QApplication(sys.argv)
myWidget = MyWidget()
myWidget.ui.show()
sys.exit(app.exec_())

Windows 上的 PySide2 问题,已打开错误 PYSIDE-767