-
Notifications
You must be signed in to change notification settings - Fork 1
/
5-disconnect.py
76 lines (54 loc) · 1.8 KB
/
5-disconnect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""Real life example of
RuntimeError: Internal C++ object (lineEdit) already deleted.
Works on PyQtx and Pyside
"""
PYSIDE = False
USE_SINGLESHOT = True
if PYSIDE:
from PySide.QtCore import Qt, QTimer
from PySide.QtGui import QApplication, QLineEdit
else:
from PyQt4.QtCore import Qt, QTimer
from PyQt4.QtGui import QApplication, QLineEdit
def onLineEditDestroyed():
print('~~~~ C++ lineEdit object destroyed')
def onSelectionChanged():
print('~~~~ Pure C++ method selectAll() called')
class LineEdit(QLineEdit):
def __init__(self):
QLineEdit.__init__(self)
self.setText("foo bar")
self.destroyed.connect(onLineEditDestroyed)
#self.selectionChanged.connect(onSelectionChanged)
def __del__(self):
print('~~~~ Python lineEdit object destroyed')
def clear(self):
"""Overriden Qt method
"""
print('~~~~ Overriden method clear() called')
QLineEdit.clear(self)
def purePythonMethod(self):
"""Pure python method.
Does not override any C++ methods
"""
print('~~~~ Pure Python method called')
self.windowTitle() # generate exception
app = QApplication([])
app.setQuitOnLastWindowClosed(False)
lineEdit = LineEdit()
lineEdit.deleteLater()
if USE_SINGLESHOT:
#QTimer.singleShot(1000, lineEdit.clear)
#QTimer.singleShot(1000, lineEdit.purePythonMethod)
QTimer.singleShot(1000, lineEdit.selectAll) # pure C++ method
else:
timer = QTimer(None)
timer.setSingleShot(True)
timer.setInterval(1000)
timer.start()
#timer.timeout.connect(lineEdit.clear)
#timer.timeout.connect(lineEdit.purePythonMethod)
timer.timeout.connect(lineEdit.selectAll) # pure C++ method
QTimer.singleShot(2000, app.quit)
app.exec_()
print('~~~~ Application exited')