I use the QfileDialog to upload a video file from my device and it works fine the problem occurs when I close the file explore without select anything, then it closes everything(main interface) and shows this error.
Process finished with exit code -1073740791 (0xC0000409)
here is a code :the QfileDialog in the upload function :
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QFileDialog, QMessageBox
from moviepy.editor import VideoFileClip
import os
global VideoPath
VideoPath=None
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(671, 389)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(100, 50, 93, 28))
self.pushButton.setObjectName("pushButton")
# to call function
self.pushButton.clicked.connect(self.check)
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(100, 140, 93, 28))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_2.clicked.connect(self.preview)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actiondjwk = QtWidgets.QAction(MainWindow)
self.actiondjwk.setObjectName("actiondjwk")
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "Upload"))
self.pushButton_2.setText(_translate("MainWindow", "Preview"))
self.actiondjwk.setText(_translate("MainWindow", "djwk"))
# upload function
def upload(self):
fname = QFileDialog.getOpenFileName(self, 'Open file',
'c:\\', "Video Files (*.mp4)")
global VideoPath
VideoPath = fname[0]
print(VideoPath)
global video
video = VideoFileClip(VideoPath)
def check(self):
try:
self.upload()
if round(video.duration) > 6:
raise durationError
except durationError:
global VideoPath
VideoPath = None
##set VideoPath to none so next steps will not work if the there is no video path
msg = QMessageBox()
msg.setIcon(QMessageBox.Critical)
msg.setText("The duration of the video should not exceed 5 seconds ")
msg.setWindowTitle("Error")
msg.exec_()
# print(VideoPath)
# print(VideoPath)
import sys
from PyQt5 import QtWidgets, uic
from test import Ui_MainWindow
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, *args, obj=None, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setupUi(self)
if __name__=="__main__":
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()
sys.exit()
# ****************************
class durationError(Exception):
...
User contributions licensed under CC BY-SA 3.0