<div>Hi,</div>
<div> </div>
<div>I have a QAbstractTableModel with a reimplemented sort() method. The model is set with a QTableView with horizontal headers. The sort() method is supposed to be called only when I click on a header section, which it successfully does, and everything is working fine in that sense. However, the sort() method is called 2 times when the application starts up when the setSortingEnabled(True) is set (if setSortingEnabled(False), then sort is not called).</div>

<div> </div>
<div>Why is the sort method called 2 times without me clicking anywhere nor calling the method explicitly? I have been looking into the order of things when starting up the application, but cannot see any difference in whatever I try. This is a problem for large data sets. The model.sort() method is given below with the output.</div>

<div> </div>
<div>Regards,</div>
<div>Bjorn</div>
<div> </div>
<div>Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on BEL, Standard<br>&gt;&gt;&gt; 2010-04-30 21:33:56,012 DEBUG table sorted!<br>2010-04-30 21:33:56,022 DEBUG table sorted!</div>
<div> </div>
<div>    def sort(self, column, order):<br>        &quot;&quot;&quot;<br>        Sort table by given column number.<br>        <br>        @param column the column clicked in the header (integer)<br>        @param order the sorting order (Qt.Descendingorder | Qt.Ascendingorder)<br>
        &quot;&quot;&quot;<br>        self.emit(SIGNAL(&quot;layoutAboutToBeChanged()&quot;))<br>        self.uncertainties = sorted(self.uncertainties, key=itemgetter(column))        <br>        if order == Qt.DescendingOrder:<br>
            self.uncertainties.reverse()<br>        self.emit(SIGNAL(&quot;layoutChanged()&quot;))<br>        logging.debug(&quot;table sorted!&quot;)</div>