使用pyqt设计了一个界面,然后写了一个读取文件的函数,其中读取文件部分代码:

curPath = QDir.currentPath()  # 获取系统当前目录
title = "打开一个文件"
filt = "文本文件(*.txt *.csv *.xlsx);;程序文件(*.h *.cpp *.py);;所有文件(*.*)"
fileName, flt = QFileDialog.getOpenFileName(self, title, curPath, filt)

链接到一个按钮,运行后在该界面点击按钮报错:

Process finished with exit code -1073740791 (0xC0000409)

以下的方法仅供参考,谨在此记录。

解决办法:
这个错误其实原因很多的,所以在pycharm打开,run > edit configuration > emulate terminal in output console勾上,再运行一次,立马提示出了什么错误。。。

我的错误:

TypeError: getOpenFileName(parent: QWidget = None, caption: str = ‘’, directory: str = ‘’, filter: str = ‘’, initialFilter: str = ‘’, options: Union[QFileDialog.Options, QFileDialog.Op
tion] = 0): argument 1 has unexpected type ‘Ui_MainWindow’

然后按照网上的方法把fileName, flt = QFileDialog.getOpenFileName(self, title, curPath, filt)中的self修改为None,该错误就解决了

还有另外一种情况会导致PyQt5报错Process finished with exit code -1073740791 (0xC0000409)(以下错误来源于然终酒肆,在此记录,以防将来遇到不好查找)

这次查它报错 果不其然

这个控件名要有下划线的

更多推荐

PyQt5报错Process finished with exit code -1073740791 (0xC0000409)