QTreeView crashing with no apparent reason
<p>I introduced a treeview in the GUI of the program I'm making and since it crashes when I attempt to change its model once it has been set.</p>

<p>The course of action is:</p>

<blockquote>
  <ul>
  <li>load the file using a file dialogue</li>
  <li>clearing the models on the interface objects (tables and treeview). The first time the treeview is not affected since there is no model in
  it.</li>
  <li>Populate the treeview model.</li>
  <li>other stuff not related to the issue.</li>
  </ul>
</blockquote>

<p>The problematic functions are;
The file loading procedure:</p>

<pre><code>def open_file(self):
        """
        Open a file
        :return:
        """
        print("actionOpen_file_click")
        # declare the dialog
        # file_dialog = QtGui.QFileDialog(self)
        # declare the allowed file types
        files_types = "Excel 97 (*.xls);;Excel (*.xlsx);;DigSILENT (*.dgs);;MATPOWER (*.m)"
        # call dialog to select the file
        filename, type_selected = QtGui.QFileDialog.getOpenFileNameAndFilter(self, 'Open file',
                                                                       self.project_directory, files_types)

        if len(filename) &gt; 0:
            self.project_directory = os.path.dirname(filename)
            print(filename)
            self.circuit = Circuit(filename, True)

            # set data structures list model
            self.ui.dataStructuresListView.setModel(self.available_data_structures_listModel)
            # set the first index
            index = self.available_data_structures_listModel.index(0, 0, QtCore.QModelIndex())
            self.ui.dataStructuresListView.setCurrentIndex(index)

            # clean
            self.clean_GUI()

            # load table
            self.display_objects_table()

            # draw graph
            self.ui.gridPlot.setTitle(os.path.basename(filename))
            self.re_plot()

            # show times
            if self.circuit.time_series is not None:
                if self.circuit.time_series.is_ready():
                    self.set_time_comboboxes()

            # tree view at the results
            self.set_results_treeview_structure()

            # populate editors
            self.populate_editors_defaults()
</code></pre>

<p>The treeview model assignation:</p>

<pre><code>def set_results_treeview_structure(self):
        """
        Sets the results treeview data structure
        @return:
        """

        # self.ui.results_treeView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
        model = QtGui.QStandardItemModel()
        # model.setHorizontalHeaderLabels(['Elements'])
        self.ui.results_treeView.setModel(model)
        # self.ui.results_treeView.setUniformRowHeights(True)

        def pass_to_QStandardItem_list(list_):
            res = list()
            for elm in list_:
                elm1 = QtGui.QStandardItem(elm)
                elm1.setEditable(False)
                res.append(elm1)
            return res

        bus_results = pass_to_QStandardItem_list(['Voltages (p.u.)', 'Voltages (kV)'])
        per_bus_results = pass_to_QStandardItem_list(['Voltage (p.u.) series', 'Voltage (kV) series',
                                                      'Active power (MW)', 'Reactive power (MVar)',
                                                      'Active and reactive power (MW, MVar)', 'Aparent power (MVA)',
                                                      'S-V curve', 'Q-V curve'])

        branches_results = pass_to_QStandardItem_list(['Loading (%)', 'Current (p.u.)',
                                                       'Current (kA)', 'Losses (MVA)'])
        per_branch_results = pass_to_QStandardItem_list(['Loading (%) series', 'Current (p.u.) series',
                                                         'Current (kA) series', 'Losses (MVA) series'])

        generator_results = pass_to_QStandardItem_list(['Reactive power (p.u.)', 'Reactive power (MVar)'])
        per_generator_results = pass_to_QStandardItem_list(['Reactive power (p.u.) series',
                                                            'Reactive power (MVar) series'])

        self.family_results_per_family = dict()

        # nodes
        buses = QtGui.QStandardItem('Buses')
        buses.setEditable(False)
        buses.appendRows(bus_results)
        self.family_results_per_family[0] = len(bus_results)
        names = self.circuit.bus_names
        for name in names:
            bus = QtGui.QStandardItem(name)
            bus.appendRows(per_bus_results)
            bus.setEditable(False)
            buses.appendRow(bus)

        # branches
        branches = QtGui.QStandardItem('Branches')
        branches.setEditable(False)
        branches.appendRows(branches_results)
        self.family_results_per_family[1] = len(branches_results)
        names = self.circuit.branch_names
        for name in names:
            branch = QtGui.QStandardItem(name)
            branch.appendRows(per_branch_results)
            branch.setEditable(False)
            branches.appendRow(branch)

        # generators
        generators = QtGui.QStandardItem('Generators')
        generators.setEditable(False)
        generators.appendRows(generator_results)
        self.family_results_per_family[2] = len(generator_results)
        names = self.circuit.gen_names
        for name in names:
            gen = QtGui.QStandardItem(name)
            gen.appendRows(per_generator_results)
            gen.setEditable(False)
            generators.appendRow(gen)

        model.appendRow(buses)
        model.appendRow(branches)
        model.appendRow(generators)
</code></pre>

<p>And the GUI "cleaning":</p>

<pre><code>def clean_GUI(self):
        """
        Initializes the comboboxes and tables
        Returns:

        """
        self.ui.tableView.setModel(None)
        if self.ui.results_treeView.model() is not None:
            self.ui.results_treeView.model().clear()

        self.ui.profile_time_selection_comboBox.clear()
        self.ui.results_time_selection_comboBox.clear()
        self.ui.gridPlot.clear()
</code></pre>

<p>The complete code can be seen <a href="https://github.com/SanPen/GridCal/blob/master/main_gui.py" rel="nofollow">here</a></p>

<p>I have seen that this behavior is usually triggered by calls outside the GUI thread by I don think this is the case.
I'd appreciate if someone could point out the problem. Again the complate code for test is <a href="https://github.com/SanPen/GridCal/blob/master/main_gui.py" rel="nofollow">here</a>.</p>