PDA

View Full Version : Application crashing when setting QAbstractTableModel's parent to QListView



MattT
8th May 2010, 04:40
I have a QListView that I'm using my own subclass of QAbstractTableModel to drive, with the usual setModel() call. However, I would like to set my QAbstractTableView's parent to the QListView when I create the model, mainly so that the model is destroyed when the widget is.

But this causes my program to crash with a EXC_BAD_ACCESS error (using QT 4.6 and Mac OS X 10.6 with XCode.) The stack trace points right back to my QAbstractTabelModel's initializer, which just passes the *parent parameter onto its own parent class.

What's wrong? I'm fairly new to QT, so I may not be understanding something completely correctly.

Thanks!

tbscope
8th May 2010, 07:55
Can you post your code please?

MattT
8th May 2010, 21:33
Aaaaand I've figured it out. It turns out that I was trying to parent the QAbstractDataModel to the QListView in my QMainWindow's initialization list. The problem was that, since I was using QT Designer, I had to call setupUi() to actually create all my widgets (my QMainWindow also subclassed the Ui::MyWindow class, which is why I could access the QListView at all.)

Moving the creation of my QAbstractDataModel to right below setupUi now allows me to parent it correctly, without crashing.

Thanks, asking for me code made me pare it down to just the essentials, which allowed me to see my problem!