I'm a new user of Qt and I'm trying to fix a persistent crashing issue that happens in my 'open file' dialogue. Whenever I open a file dialogue to select a file and decide to hit cancel instead, it causes python to stop working. This is what the code looks like right now:
# get save file
savefile, _ = QtWidgets.QFileDialog.getOpenFileName(self, "Open file", "", "Files (*.mat)")
self.matlocation = savefile
I've tried using:
savefile, _ = QtWidgets.QFileDialog.getOpenFileName(self, "Open file", "", "Files (*.mat)")
if(!fileName.isEmpty()&& !fileName.isNull()){
self.matlocation = savefile
}
but this is still causing crashes. Am I missing something?
Thanks in advance.
Edit It's part of a larger function: So it's part of a function from a larger .py. The function as it stands starts by loading in a mat file:
def loadmat(self):
from PyQt5 import QtWidgets
import functions.plotting as plot
# get save file
savefile, _ = QtWidgets.QFileDialog.getOpenFileName(self, "Open file", "", "Files (*.mat)")
self.matlocation = savefile
# set mat location in GUI box
self.gui.samplelocBox.setPlainText(self.matlocation)