Reputation: 1
I wrote a simple class for notifying user using tray balloon message. Here is the code:
# -*- coding: utf8 -*-
import sys
import time
from PyQt4 import QtGui
class TrayInformer():
def __init__(self, icon_file):
self.app = QtGui.QApplication(sys.argv)
self.app.setQuitOnLastWindowClosed(False)
self.tray_icon = QtGui.QSystemTrayIcon(
QtGui.QIcon(icon_file)
)
def notify(self, title, message, wait_time=1000):
self.tray_icon.show()
self.tray_icon.showMessage(title, message)
time.sleep(wait_time / 1000)
self.tray_icon.hide()
inf = TrayInformer('timeico.ico')
inf.notify('Error', 'Connection refused', 5000)
inf.notify('test', 'test', 500)
After running it I sometimes get: Process finished with exit code -1073741819 (0xC0000005)
. What could be the problem?
Upvotes: 0
Views: 124
Reputation: 2423
Try to instantiate QSystemTrayIcon with parent specified. I've had resembling random crashes on exit, and surprisingly tray icon appeared to cause the problem
<...> the problem is probably the random order in which C++ instances get destroyed. Explicitly del'ing a object, or giving it an appropriate parent is the best way to deal with it. QSystemTrayIcon still crashed app (PyQt4 4.9.1)
Upvotes: 1