PyQt5 crashes silently upon trying to clear a table
-
Hi,
I have a QTableWidget (Item-based) called h2h_table that gets assigned 10 rows, 10 columns, and items containing 1 character long strings.
Upon creating a function to reset everything related to the program, I noticed that h2h_table.clear() will cause the program to crash silently. This does not occur with the other tables in the program. As far as I can tell, I'm not doing anything different to h2h_table that I'm not doing to the other tables.
Reset Everything Function:
def reset_everything(): window.h2h = {} window.standings = {} window.matches = [] window.selected_matches = [] window.second_half_wins = {} window.scenarios = [] window.team_list_widget.clear() window.match_list_widget.clear() window.add_match_team1_dropdown.clear() window.add_match_team1_dropdown.setCurrentIndex(-1) window.add_match_team2_dropdown.clear() window.add_match_team2_dropdown.setCurrentIndex(-1) window.edit_match_team1_dropdown.clear() window.edit_match_team1_dropdown.setCurrentIndex(-1) window.edit_match_team2_dropdown.clear() window.edit_match_team2_dropdown.setCurrentIndex(-1) for match_field in window.match_fields: match_field.clear() match_field.setCurrentIndex(-1) match_field.setEnabled(False) window.perc_playoffs_table.clear() window.num_scenarios_no_ties_table.clear() window.num_scenarios_ties_table.clear() window.percent_scenarios_no_tie_table.clear() window.percent_scenarios_ties_table.clear() window.num_scenarios_worst_table.clear() window.percent_scenarios_worst_table.clear() window.h2h_table.clear() # Clearing this table crashes the program silently
h2h_table construction:
def load_h2h(): window.h2h_table.setColumnCount(len(window.h2h)) window.h2h_table.setRowCount(len(window.h2h)) for y, (team, team_h2h) in enumerate(window.h2h.items()): item = QtWidgets.QTableWidgetItem(team) window.h2h_table.setHorizontalHeaderItem(y, item) window.h2h_table.setVerticalHeaderItem(y, item) for x, (opp_team, wins) in enumerate(team_h2h.items()): item = QtWidgets.QTableWidgetItem(str(wins)) window.h2h_table.setItem(y, x, item)
Any suggestions on how to diagnose and fix this? I also tried a few methods of getting an error to print, but nothing is working.
I'm on Windows 10.
-
Hi and welcome to devnet,
Can you reproduce that crash with a minimal script only containing a QTableWidget ?