Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PyQt5 crashes silently upon trying to clear a table

PyQt5 crashes silently upon trying to clear a table

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 2 Posters 313 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Leothechosen
    wrote on last edited by Leothechosen
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Can you reproduce that crash with a minimal script only containing a QTableWidget ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        Can you reproduce that crash with a minimal script only containing a QTableWidget ?

        L Offline
        L Offline
        Leothechosen
        wrote on last edited by
        #3

        @SGaist Well never mind, it appears I've fixed it by changing all "setHorizontalHeaderItem" to "setHorizontalHeaderLabels", and same with vertical headers.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved