I'm creating this application in Python that talks with Outlook and retrieve some data about the amount of mails in each folder and some other stuff and I'm using PyQt5 to do so.
But some werid thing happened when I assigned a signal to a function:
self.table_widget.itemDoubleClicked.connect(self.some_function)
If I double right-click this item, everything runs just fine. But if I do it with the left-click , it just freezes, and then crashes without any error screen whatsoever (usually if you execute the program, when it crashes you can see some stack on the console behind, right? In this case literally nothing shows up).
I'm not sure if I'm using he signals thing right, so there might be something...?
Anyways, since no error occurred, I tried to put some prints to see where it would crash, but it turns out that the t2 screen loads just fine, and apparently it crashes when the code goes back to the main loop...? I don't know, it's impossible for me to debug that stuff.
I'll try to put here only the essential code so it gets easier to see the mistake, but I can show some details if this is not enough.
EDIT
As requested, I did a minimum reproducible example below, it does crash in the same way:
from PyQt5.QtCore import QDateTime, Qt, QTimer, pyqtSignal
from PyQt5.QtWidgets import QApplication, QMainWindow, QDialog, QTableWidgetItem
from PyQt5 import uic
import sys, os
class t0(QMainWindow):
switch_window = pyqtSignal()
def __init__(self):
super(t0, self).__init__()
uic.loadUi(Controller.application_path + r'\UI\t0.ui', self)
#This .ui file has pretty much a button to click
self.btn_ok.clicked.connect(self.onButtonClick1)
def onButtonClick1(self):
self.switch_window.emit()
class t1(QDialog):
switch_window = pyqtSignal()
def __init__(self, parent=None):
super(t1, self).__init__(parent)
uic.loadUi(Controller.application_path + r'\UI\t1.ui', self)
#This .ui file has a QTableWidget
self.tw_indi.setColumnCount(1)
self.tw_indi.setRowCount(1)
self.tw_indi.setItem(0, 0, QTableWidgetItem("*"))
self.tw_indi.itemDoubleClicked.connect(self.direcionar_detalhes)
def direcionar_detalhes(self, item):
self.switch_window.emit()
class t2(QDialog):
switch_window = pyqtSignal(str)
def __init__(self, parent=None):
super(t2, self).__init__(parent)
uic.loadUi(Controller.application_path + r'\UI\t2.ui', self)
#This .ui file is identical as the t1.ui, just some minor changes
class Controller():
controller = None
#questões técnicas do módulo os com pyinstaller
if getattr(sys, 'frozen', False):
application_path = sys.exec_prefix
else:
application_path = os.path.dirname(os.path.abspath(__file__))
tela = None
app = QApplication(sys.argv)
def __init__(self):
Controller.controller = self
self.mostra_carregamento()
sys.exit(Controller.app.exec_())
def mostra_carregamento(self):
self.view = t0()
self.view.switch_window.connect(self.mostra_indicador)
self.view.show()
def mostra_indicador(self):
self.view.close()
self.view = t1()
self.view.switch_window.connect(self.sinal_indicador)
self.view.show()
def sinal_indicador(self):
self.view.close()
self.view = t2()
self.view.show()
if __name__ == '__main__':
control = Controller()
EDIT 2
Here's the link for the ui's: https://drive.google.com/file/d/1-iFNaWUGtJ4687nTcTFtb7WRKUL37als/view?usp=drivesdk
The problem is not the signal, but when you want to reuse the same variable for a new window, you are eliminating the memory of that object that is still visible and therefore running, generating unreserved memory access. The solution is to use different variable names:
class Controller:
# ...
def mostra_carregamento(self):
self.view0 = t0()
self.view0.switch_window.connect(self.mostra_indicador)
self.view0.show()
def mostra_indicador(self):
self.view0.close()
self.view1 = t1()
self.view1.switch_window.connect(self.sinal_indicador)
self.view1.show()
def sinal_indicador(self):
self.view1.close()
self.view2 = t2()
self.view2.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.