Ran into an issue that seems like the event loop is blocked (or I didn't start one?) and I haven't been able to chase it down.
The GUI comes up, and the menus are responsive, but clicking File->Open, which should create an near immediate print statement doesn't happen.
I know I have the correct signal mapped to the slot because as soon as you do a File->Quit or close the window, the print statement comes out.
I implemented this same example in C++ with the identical UI file and it works as expected.
Problem exhibits in the following configurations:
Windows 10, Python 3.6.4, pyside2-5.11.1a1.dev1530708810518
Windows 10, Python 2.7.14, pyside2-5.11.0a1.dev1528378291
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_())
Issue with PySide2 on Windows, opened bug PYSIDE-767