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

On Wed, Mar 30, 2011 at 8:45 PM, Keith Gunderson <[email protected]> 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.
>
> 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()
>
>
> _______________________________________________
> PySide mailing list
> [email protected]
> http://lists.pyside.org/listinfo/pyside
>
>
_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside

Reply via email to