Python - PyQt QInputDialog.getItem 应用程序掉线的取消按钮问题
Python - PyQt QInputDialog.getItem Cancel button problem with app drops
调用 QInputDialog.getItem 后,如果我 select 选择该选项并按确定,一切正常。如果我按取消,程序就会崩溃并出现以下错误:
Process finished with exit code -1073740791 (0xC0000409)
调试后这个错误是我没有将数据加载到变量中:
(<class 'UnboundLocalError'>, UnboundLocalError("local variable 'link' referenced before assignment"), <traceback object at 0x000001BC8209DE00>)
如何处理这个问题,以便在按下“取消”后程序继续运行而不会崩溃?
query = "SELECT name FROM datasets"
datasets = cur.execute(query).fetchall()
items = ()
for dataset in datasets:
items += dataset
item, ok = QInputDialog.getItem(self, "select input dialog", "list of languages", items, 0, False)
if ok and item:
query = "SELECT name, file FROM datasets"
datasets = cur.execute(query).fetchall()
for dataset in datasets:
if dataset[0] == item:
link = dataset[1]
dataset_name = "Meno datasetu: " + str(dataset[0].split("-")[0])
在访问之前尝试初始化link
link = None
item, ok = QInputDialog.getItem(self, "select input dialog", "list of languages", items, 0, False)
if ok and item:
...
调用 QInputDialog.getItem 后,如果我 select 选择该选项并按确定,一切正常。如果我按取消,程序就会崩溃并出现以下错误:
Process finished with exit code -1073740791 (0xC0000409)
调试后这个错误是我没有将数据加载到变量中:
(<class 'UnboundLocalError'>, UnboundLocalError("local variable 'link' referenced before assignment"), <traceback object at 0x000001BC8209DE00>)
如何处理这个问题,以便在按下“取消”后程序继续运行而不会崩溃?
query = "SELECT name FROM datasets"
datasets = cur.execute(query).fetchall()
items = ()
for dataset in datasets:
items += dataset
item, ok = QInputDialog.getItem(self, "select input dialog", "list of languages", items, 0, False)
if ok and item:
query = "SELECT name, file FROM datasets"
datasets = cur.execute(query).fetchall()
for dataset in datasets:
if dataset[0] == item:
link = dataset[1]
dataset_name = "Meno datasetu: " + str(dataset[0].split("-")[0])
在访问之前尝试初始化link
link = None
item, ok = QInputDialog.getItem(self, "select input dialog", "list of languages", items, 0, False)
if ok and item:
...