Skip to content

Commit ff812b7

Browse files
authored
Merge pull request #173 from abstractfactory/implement152
Implement #152
2 parents a646d3e + 787de74 commit ff812b7

File tree

8 files changed

+1010
-443
lines changed

8 files changed

+1010
-443
lines changed

CAVEATS.md

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ There are cases where Qt.py is not handling incompatibility issues.
88
- [QtWidgets.QAction.triggered](#qtwidgetsqactiontriggered)
99
- [QtGui.QRegExpValidator](#qtguiqregexpvalidator)
1010
- [QtWidgets.QHeaderView.setResizeMode](#qtwidgetsqheaderviewsetresizemode)
11+
- [QtWidgets.qApp](#qtwidgetsqapp)
1112

1213
<br>
1314
<br>
@@ -121,25 +122,25 @@ PySide allows for a `result=None` keyword param to set the return type. PyQt4 cr
121122

122123
```python
123124
# PySide
124-
>>> from Qt import QtCore, QtGui
125-
>>> slot = QtCore.Slot(QtGui.QWidget, result=None)
125+
>>> from Qt import QtCore, QtWidgets
126+
>>> slot = QtCore.Slot(QtWidgets.QWidget, result=None)
126127
```
127128

128129
```python
129130
# PyQt4, Python2
130-
>>> from Qt import QtCore, QtGui
131-
>>> slot = QtCore.Slot(QtGui.QWidget)
132-
>>> slot = QtCore.Slot(QtGui.QWidget, result=None)
131+
>>> from Qt import QtCore, QtWidgets
132+
>>> slot = QtCore.Slot(QtWidgets.QWidget)
133+
>>> slot = QtCore.Slot(QtWidgets.QWidget, result=None)
133134
Traceback (most recent call last):
134135
...
135136
TypeError: string or ASCII unicode expected not 'NoneType'
136137
```
137138

138139
```python
139140
# PyQt4, Python3
140-
>>> from Qt import QtCore, QtGui
141-
>>> slot = QtCore.Slot(QtGui.QWidget)
142-
>>> slot = QtCore.Slot(QtGui.QWidget, result=None)
141+
>>> from Qt import QtCore, QtWidgets
142+
>>> slot = QtCore.Slot(QtWidgets.QWidget)
143+
>>> slot = QtCore.Slot(QtWidgets.QWidget, result=None)
143144
Traceback (most recent call last):
144145
...
145146
TypeError: bytes or ASCII string expected not 'NoneType'
@@ -277,4 +278,36 @@ Or a conditional.
277278
... header.setResizeMode(QtWidgets.QHeaderView.Fixed)
278279
... else:
279280
... header.setSectionResizeMode(QtWidgets.QHeaderView.Fixed)
281+
```
282+
283+
284+
#### QtWidgets.qApp
285+
286+
In [Strict Mode](https://github.com/mottosso/Qt.py#qt_strict), `qApp` is not included in Qt.py due to the way Qt keeps this up to date with the currently active QApplication.
287+
288+
Qt implicitly updates this variable through monkey patching whenever a new QApplication is instantiated. This means that our variable quickly goes out of date and is not updated at the same time.
289+
290+
```python
291+
# PySide2
292+
>>> import os
293+
>>> os.environ["QT_STRICT"] = "1"
294+
>>> from Qt import QtWidgets
295+
>>> "qApp" in dir(QtWidgets)
296+
False
297+
```
298+
299+
##### Workaround
300+
301+
Use `QApplication.instance()` instead.
302+
303+
Technically, there is no difference between the two, apart from more characters to type.
304+
305+
```python
306+
# PySide2
307+
>>> import os
308+
>>> os.environ["QT_STRICT"] = "1"
309+
>>> from Qt import QtWidgets
310+
>>> app = QtWidgets.QApplication(sys.argv)
311+
>>> app == QtWidgets.QApplication.instance()
312+
True
280313
```

0 commit comments

Comments
 (0)