V
V
Vitaly2015-01-25 02:54:44
Python
Vitaly, 2015-01-25 02:54:44

How did it happen that it works :)?

There is this code:

class BugWindow (QtGui.QWidget, Create_bug_report.Ui_Bug):
    def __init__(self, parent=None, flags=None):
        QtGui.QWidget.__init__(self, parent) 
        self.setWindowFlags(flags)      
        self.setupUi(self)
    def __call__(self):
        #print(self.parentWidget())
        self.show() 
....
try:
...
raise FileNotFoundError

except FileNotFoundError as e:
        app = QtGui.QApplication(sys.argv) 
        bug_window = BugWindow(flags=QtCore.Qt.Window)
        bug_window.show()
        bug_window.err_label.setText(r'<html><head/><body><p align="center"><span style=" font-size:10pt; font-weight:600;">Error message:</span></p><p>'+str(e) +r'</p><p> </p></body></html>')             
        sys.exit(bug_window.exec_())
finally:        
        cnfg.write(options_file)
        options_file.close         
        sys.exit(app.exec_())

before I put sys.exit(bug_window.exec_()) instead of sys.exit(app.exec_()) in the exception catch, the window with the error was closed but the application process did not terminate
Who fumbles in exceptions and PyQt can you explain how it works?
just please hurry up...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fedor Kichatov, 2015-03-28
@vitosua

The 'window close button click' event closes the window by default, but does not kill the main event-loop fired by the 'app.exec_()' statement.
The QApplication event-loop usually stops itself when the last opened window closes.
But this only applies to windows without a parent and with the Qt.WA_QuitOnClose flag.
pyqt.sourceforge.net/Docs/PyQt4/qapplication.html#...
Perhaps this flag is not set on the BugWindow.
You can add this flag to the BugWindow widget:
bug_window.setWindowFlags(bug_window.windowFlags() | QtCore.Qt.WA_QuitOnClose)
Or bind the 'window closed' event to a stop/kill event-loop:
class BugWindow(...):
def __init__ (...):
self.closed.connect(QtCore.QCoreApplication.instance().quit)
zetcode.com/gui/pyqt4/firstprograms

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question