[PySide] Some crashes using QTableWidget

358 views
Skip to first unread message

Keith Gunderson

unread,
Mar 30, 2011, 2:45:58 PM3/30/11
to pys...@lists.pyside.org

Hello,

New PySide user here with an issue that my app/script crashes sometimes when QTableWidget.clear() is called.  It is reproducible but I can't understand why it crashes when it does.

The script fills the table with data from an array that meet some criteria.  I select a cell/ row and press a button that causes all the data from the selected row to be written to a file.  Then the table is cleared and re-filled with a new set of data.  If I select a certain cell from certain sets, the crash occurs.  But selecting the same cell in other sets doesn't cause the crash.  Selecting a different cell in the same row/ same set as 'crasher selection' can prevent the crash.  Crashes occur perhaps about 2% of the time.  I can't understand why it occurs, but then again I know very little about Qt and its MVC classes.

Here is some code:

The window:

from PySide import QtCore, QtGui

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayoutWidget = QtGui.QWidget(self.centralwidget)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(170, 20, 160, 80))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
        self.verticalLayout = QtGui.QVBoxLayout(self.verticalLayoutWidget)
        self.verticalLayout.setMargin(0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.tableWidget = QtGui.QTableWidget(self.centralwidget)
        self.tableWidget.setGeometry(QtCore.QRect(10, 110, 781, 451))
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setColumnCount(0)
        self.tableWidget.setRowCount(0)


The app:

def main():

    array1 = numpy.loadtxt(open("aa_count.csv"), delimiter=',', dtype={'names' :('dh', 'ds', 'count' ), 'formats': ('f4', 'f4', 'i4' )  }  )
    array2 = numpy.loadtxt(open("aa_full.csv"), delimiter=',', dtype={'names' :('id', 'dh', 'ds', 'name1', 'name2', 'name3', 'name4' ), 'formats': ('i4', 'f4', 'f4', 'S2', 'S2', 'S2', 'S2' )  }  )

    writer1 = csv.writer(open("aa_prime.csv", "wb"), dialect = 'excel' )

    app = QApplication(sys.argv)
    frame = MainWindow(dataArray = array2, dataCounts = array1, outWriter=writer1)
    frame.show()
   

    app.exec_()
       


The Window Class


class MainWindow( QMainWindow, Ui_MainWindow):
    def __init__(self, parent= None, dataArray=None, dataCounts = None, outWriter = None):
        super( MainWindow,self).__init__(parent)
        self.setupUi(self)
        self.outWriter = outWriter
        self.dataArray = dataArray
        self.dataCounts = dataCounts
        self.dataCountRow = 0
        self.tableWidget.setColumnCount( 7  )

#filling the table

    def showGroup(self):
        self.tableWidget.clear()
        self.tableWidget.setHorizontalHeaderLabels( self.dataArray.dtype.names  )
        dhval = self.dataCounts[self.dataCountRow ] ['dh']
        dsval = self.dataCounts[self.dataCountRow ] ['ds']
        activeRows = self.dataArray[ (self.dhs == dhval) * (self.dss == dsval)  ]
        self.rowNumber.setText( str( self.dataCountRow + 1 ) )
        irow = 0
        for rowX in activeRows:
            if not self.filterRow( rowX):
                irow += 1
        self.tableWidget.setRowCount( irow )
        irow = 0
        for rowX in activeRows:
            if not self.filterRow( rowX):
                self.tableWidget.setItem( irow, 0,  QTableWidgetItem(self.tr(str( rowX[0]   ))) )
                self.tableWidget.setItem( irow, 1,  QTableWidgetItem(self.tr(str( rowX[1]   ))) )
                self.tableWidget.setItem( irow, 2,  QTableWidgetItem(self.tr(str( rowX[2]   ))) )
                self.tableWidget.setItem( irow, 3,  QTableWidgetItem(self.tr(str( rowX[3]   ))) )
                self.tableWidget.setItem( irow, 4,  QTableWidgetItem(self.tr(str( rowX[4]   ))) )
                self.tableWidget.setItem( irow, 5,  QTableWidgetItem(self.tr(str( rowX[5]   ))) )
                self.tableWidget.setItem( irow, 6,  QTableWidgetItem(self.tr(str( rowX[6]   ))) )
                irow += 1
        self.tableWidget.setFocus()


#getting the data out of the table
    def acceptSelectedRow(self):
        import pdb
#        pdb.set_trace()
        item = self.tableWidget.currentItem()
        if item and  item.row() >= 0:
            rowNum = item.row()
            rows = []
            for col in xrange(self.tableWidget.columnCount() ):
                it = self.tableWidget.item( rowNum, col)
                rows.append(  it.text() )
        if self.outWriter:
            self.outWriter.writerow ( rows )
        item = None
        self.nextGroup()

Erik Janssens

unread,
Mar 30, 2011, 3:17:55 PM3/30/11
to Keith Gunderson, pys...@lists.pyside.org
it might help to run QT in debug mode

the whole MVC stuff has a lot of asserts, so you might
be informed earlier on on what goes wrong

_______________________________________________
PySide mailing list
PyS...@lists.pyside.org
http://lists.pyside.org/listinfo/pyside


Keith Gunderson

unread,
Mar 30, 2011, 3:53:59 PM3/30/11
to pys...@lists.pyside.org

Thank you.  Is there a HOW-TO for doing that?  My initial guess is that I have to:

1. Download the QT source (I'll use Qt-win-opensource-4.7.2.-vs2008)
2: build the debug versions
3:  copy somewhere
4: edit my qt.conf located at c:\Python26

Is that right?



--- On Wed, 3/30/11, Erik Janssens <Erik.J...@conceptive.be> wrote:

Erik Janssens

unread,
Mar 30, 2011, 4:01:40 PM3/30/11
to Keith Gunderson, pys...@lists.pyside.org
that 'might' work, I'm not sure

you could try to just copy the debug dll's over the dll's you're using now
(not sure how that goes on Windows), not sure if you need to recompile
PySide

I have my own Windows build to be able to fine tune
everything ( http://www.python-camelot.com/cpd.html ),
unfortunately I don't have a debug build for windows available
yet

If you have access to a Linux machine, things might be a lot easier

Keith Gunderson

unread,
Mar 30, 2011, 4:59:14 PM3/30/11
to pys...@lists.pyside.org
Using linux is no problem.  I have an openSuse11.2 VM on my machine.

I've installed pyside and its reqs.  I even easy_installed your camelot to check it out, BTW.

I'm not quite sure what I need to do now.  Something similar to my plan for Windows, or something else.

Keith Gunderson

unread,
Mar 30, 2011, 5:00:53 PM3/30/11
to pys...@lists.pyside.org

I forgot to add that I can reproduce this issue now in non-debug mode on linux:

I see the following on the console

*** glibc detected *** python: double free or corruption (fasttop): 0x0885d2c0 ***




--- On Wed, 3/30/11, Keith Gunderson <kr...@yahoo.com> wrote:
-----Inline Attachment Follows-----

Erik Janssens

unread,
Mar 30, 2011, 5:31:42 PM3/30/11
to Keith Gunderson, pys...@lists.pyside.org
indeed something similar

first try to install the qt - development packages for your distro, to
make sure all headers etc are installed

or you might find everything on
https://build.opensuse.org/

Keith Gunderson

unread,
Mar 30, 2011, 6:06:10 PM3/30/11
to erik.j...@conceptive.be, pys...@lists.pyside.org
done.

I'm glad you're helping me because I'm really lost when I try to find info from nokia's website.

I'm not sure what to do next.

Erik Janssens

unread,
Mar 31, 2011, 12:44:01 AM3/31/11
to Keith Gunderson, pys...@lists.pyside.org
this page has the build commands for a debug build of qt itself

http://downloads.conceptive.be/downloads/camelot/doc/sphinx/build/advanced/debug.html

but you will need to build pyside afterwards as well

Matti Airas

unread,
Mar 31, 2011, 5:04:35 AM3/31/11
to pys...@lists.pyside.org
On 30.03.2011 21:45, ext Keith Gunderson wrote:
>
> Hello,
>
> New PySide user here with an issue that my app/script crashes
> sometimes when QTableWidget.clear() is called. It is reproducible but
> I can't understand why it crashes when it does.

Hi Keith,

If you're not very much into debugging the internals of PySide itself, I
wouldn't bother with rebuilding a debug version of PySide. Instead,
report the issue in our Bugzilla at http://bugs.pyside.org. Since this
is, according to your description, a reproducible crasher bug, it's by
definition a high-priority issue and should be resolved in a short time.

Cheers,

ma.

Erik Janssens

unread,
Mar 31, 2011, 1:19:00 PM3/31/11
to Matti Airas, pys...@lists.pyside.org
while this might very well be a PySide bug, I doubt it

the QT MVC classes are full with ASSERT statements and it's
very easy to 'abuse' them ...

Keith Gunderson

unread,
Apr 1, 2011, 2:54:15 PM4/1/11
to pys...@lists.pyside.org
Well, I reported the issue (#799).

I also built a debug version of pyside and qt.  The only output I get when the issue happens is:

*** glibc detected *** python: double free or corruption (fasttop): 0x088f03a0 ***

Then, the app freezes and I have to kill it.


From: Erik Janssens <Erik.J...@conceptive.be>
To: Matti Airas <matti....@nokia.com>
Cc: pys...@lists.pyside.org
Sent: Thu, March 31, 2011 12:19:00 PM

Subject: Re: [PySide] Some crashes using QTableWidget

Erik Janssens

unread,
Apr 2, 2011, 4:56:08 AM4/2/11
to Keith Gunderson, pys...@lists.pyside.org

hmm...sorry to advise you to go through the trouble of making
a debug build, but now that you have one, you can run your
app in gdb to see where exactly this occurs...

On Fri, 2011-04-01 at 11:54 -0700, Keith Gunderson wrote:
> Well, I reported the issue (#799).
>
> I also built a debug version of pyside and qt. The only output I get
> when the issue happens is:
>
> *** glibc detected *** python: double free or corruption (fasttop):
> 0x088f03a0 ***
>
> Then, the app freezes and I have to kill it.
>
>
>

> ______________________________________________________________________

Keith Gunderson

unread,
Apr 5, 2011, 3:33:38 PM4/5/11
to erik.j...@conceptive.be, pys...@lists.pyside.org
Well, I never could get my app to run in debug mode using the openSUSE system.  That distribution isn't really my cup of tea.

I built up a debian system using some spare cycles in the meantime.  I have no issue running my app in gdb on debian.  Unfortunately, it never crashes on that system (debug more or not.)

I did have to comment out one setMargin line in my mainmenu.py file on the debian system (QVBoxLayout object had no attribute 'setMargin').  But other than that, the app works perfectly.




From: Erik Janssens <Erik.J...@conceptive.be>
To: Keith Gunderson <kr...@yahoo.com>
Cc: pys...@lists.pyside.org
Sent: Sat, April 2, 2011 3:56:08 AM
Reply all
Reply to author
Forward
0 new messages