QSystemTrayIcon makes python crash



QSystemTrayIcon使应用程序崩溃。我在控制台中没有收到错误。Windows说AppHangB1。但是,有时它可以工作几次,有时它会在首次显示上下文菜单时崩溃。

编辑:

这是我的代码分解为最重要的事情:

class SystemTrayIcon(QSystemTrayIcon):
def __init__(self, icon, parent=None):
QSystemTrayIcon.__init__(self, icon, parent)
menu = QMenu()
showAction = menu.addAction("Fenster anzeigen")
exitAction = menu.addAction("Beenden")
menu.setStyleSheet("QMenu{background-color:white; margin:2px; "
"font: 75 10pt Trebuchet MS;} "
"QMenu::item:selected{background-color:#8e0000;}")
self.setContextMenu(menu)
self.setToolTip("KOSE")
exitAction.triggered.connect(self.exit)
showAction.triggered.connect(self.show_window)
def exit(self):
sys.exit()
def show_window(self):
if (loading_screen_window.windowOpacity() == 0.0):
loading_screen_window.fadeIN()
class CancelWindow(QWidget):
def __init__(self):
super(CancelWindow, self).__init__()
loader = QUiLoader()
file = QFile("cancel.ui")
file.open(QFile.ReadOnly)
global cancel_screen
cancel_screen = loader.load(file, self)
file.close()
self.initUI()
def initUI(self):
#some init stuff like window pos, button- function connects...
def fadeIN(self):
#window fade in animation
def fadeOUT(self, exit):
#fade out animation
def ja(self):
#button func
self.fadeOUT(True)
def nein(self):
#button func
self.fadeOUT(False)
kunden_screen.lbl_opacity.hide()
kunden_screen.setEnabled(True)
def exit_app(self):
QCoreApplication.exit() 
class LoadingScreen(QWidget):
def __init__(self):
super(LoadingScreen, self).__init__()
loader = QUiLoader()
file = QFile("loading_screen.ui")
file.open(QFile.ReadOnly)
global loading_screen
loading_screen = loader.load(file, self)
file.close()
self.initUI()
#Config Thread
self.config_thread = config()
self.config_thread.finished.connect(self.config_finished)
#Config Thread starten
self.config_thread.start()
def initUI(self):
#window init
def fadeIN(self):
#fade animation
def fadeOUT(self):
#fade animation
def config_finished(self):
#function thats called when config thread is finished
class KundenSelect(QWidget):
connected = 0
cursor = None
conn_database = None
def __init__(self):
super(KundenSelect, self).__init__()
loader = QUiLoader()
file = QFile("kunden.ui")
file.open(QFile.ReadOnly)
global kunden_screen
kunden_screen = loader.load(file, self)
file.close()
self.initUI()
def initUI(self):      
#window init
class config(QThread):  
def run(self):
#config thread, reading files, database connection ...
app = QApplication(sys.argv)
global loading_screen_window
loading_screen_window = LoadingScreen()
global kunden_screen_window
kunden_screen_window = KundenSelect()
kunden_screen.lbl_opacity.hide()
kunden_screen_window.hide()
global cancel_screen_window
cancel_screen_window = CancelWindow()
cancel_screen_window.hide()
trayIcon = SystemTrayIcon(QIcon("icon.png"), parent=app)
trayIcon.show()
sys.exit(app.exec_())  

我已经用谷歌搜索过,但没有找到任何解决方案。我使用的是 PySide2 和 Qt5。

谢谢

这段代码似乎在工作,只是改变了信号/插槽语法

class SystemTrayIcon(QSystemTrayIcon):
def __init__(self, icon, parent=None):
QSystemTrayIcon.__init__(self, icon, parent)
menu = QMenu()
showAction = menu.addAction("Fenster anzeigen")
exitAction = menu.addAction("Beenden")
menu.setStyleSheet("QMenu{background-color:white; margin:2px; "
"font: 75 10pt Trebuchet MS;} "
"QMenu::item:selected{background-color:#8e0000;}")
self.setContextMenu(menu)
self.setToolTip("KOSE")
exitAction.triggered.connect(self.exit)
showAction.triggered.connect(self.show_window)
def exit(self):
sys.exit()
def show_window(self):
print("xxxxxx")
# if (loading_screen_window.windowOpacity() == 0.0):
# loading_screen_window.fadeIN()
app = QApplication(sys.argv)
trayIcon = SystemTrayIcon(QIcon("icon.png"), parent=app)
trayIcon.show()
sys.exit(app.exec_())

使用Pyside(不是Pyside2(,但我认为这里不会有那么不同。

相关内容

  • 没有找到相关文章

最新更新