Qt-interest Archive, April 2007
Crash in my after my delegate creates it's editor....
Message 1 in thread
I am using Qt 4.2.3.
I am having a problem with a custom delegate for a table view. When I try and
create the editor, I get a crash/core dump in Qt when it is trying to set the tab order.
The declaration of the delegate is:
class ChoiceListDelegate: public QItemDelegate
{
Q_OBJECT
public:
ChoiceListDelegate(
QStringList const & choices,
QObject *parent = NULL)
:
QItemDelegate(parent),
_choices (choices)
{}
virtual ~ChoiceListDelegate() {};
virtual QWidget *createEditor(
QWidget *parent,
const QStyleOptionViewItem & option,
const QModelIndex & index) const;
virtual void setEditorData(
QWidget *editor,
const QModelIndex & index) const;
virtual void setModelData(
QWidget *editor,
QAbstractItemModel *model,
const QModelIndex & index) const;
virtual void paint(
QPainter *painter,
const QStyleOptionViewItem & option,
const QModelIndex & index) const;
private:
QStringList _choices;
};
The ::createEditor method implementation:
QWidget *ChoiceListDelegate::createEditor(
QWidget *,
const QStyleOptionViewItem &,
const QModelIndex &) const
{
CentralComboBox *combo = new CentralComboBox();
int count = _choices.count();
for (int i = 0; (i < count); i++)
combo->addItem(_choices[i]);
return combo;
}
And main:
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QWidget win;
QTableView *view = new QTableView(&win);
MyTableModel *model = new MyTableModel();
view->setModel(model);
QStringList choices << "Choice 1" << "Choice 2" << "Choice 3";
ChoiceListDelegate *delegate = new ChoiceListDelegate(choices);
view->setItemDelegateForColumn(5, delegate);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(view);
win.setLayout(vbox);
win.resize(500, 700);
win.show();
return app.exec();
}
Under gdb, the stack trace:
ASSERT: "first->d_func()->focus_next->d_func()->focus_prev == first" in file kernel/qwidget.cpp, line 4433
Program received signal SIGABRT, Aborted.
[Switching to Thread -1223919936 (LWP 8234)]
0xffffe410 in __kernel_vsyscall ()
Current language: auto; currently c
(gdb) where
#0 0xffffe410 in __kernel_vsyscall ()
#1 0xb7111ef1 in raise () from /lib/tls/libc.so.6
#2 0xb711383b in abort () from /lib/tls/libc.so.6
#3 0xb740a538 in qt_message_output (msgType=QtFatalMsg,
buf=0xbfbcbb30 "ASSERT: \"first->d_func()->focus_next->d_func()->focus_prev == first\" in file kernel/qwidget.cpp, line 4433") at global/qglobal.cpp:2000
#4 0xb740a58a in qFatal (msg=0xb750febc "ASSERT: \"%s\" in file %s, line %d")
at global/qglobal.cpp:2238
#5 0xb740a5f0 in qt_assert (
assertion=0xb7df37a0 "first->d_func()->focus_next->d_func()->focus_prev == first", file=0xb7df2cc1 "kernel/qwidget.cpp", line=4433)
at global/qglobal.cpp:1760
#6 0xb78e52dd in QWidget::setTabOrder (first=0x80f2a30, second=0x81f1a98)
at kernel/qwidget.cpp:4433
#7 0xb7cfed21 in QAbstractItemViewPrivate::editor (this=0x80f3718,
index=@0xbfbcdc88, options=@0xbfbcdc38)
at itemviews/qabstractitemview.cpp:3184
#8 0xb7cfee79 in QAbstractItemViewPrivate::openEditor (this=0x80f3718,
index=@0x81c4a68, event=0x0) at itemviews/qabstractitemview.cpp:3309
What am I doing wrong?
_____________________________
Susan Macchia
mailto:susan@xxxxxxxxxxxx
http://www.smacchia.net
_____________________________
--
[ signature omitted ]