我在 Mainwindow.h 里定义了
class UserIDDelegate : public QItemDelegate
{
Q_OBJECT
public :
UserIDDelegate(QObject parent = 0): QItemDelegate(parent) { }
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QLineEdit *editor = new QLineEdit(parent);
QRegExp regExp( "[0-9]{0,10}" );
editor->setValidator( new QRegExpValidator(regExp, parent));
return editor;
}
void setEditorData(QWidget *editor, const QModelIndex &index) const
{
QString text = index.model()->data(index, Qt::EditRole).toString();
QLineEdit *lineEdit = static_cast <QLineEdit>(editor);
lineEdit->setText(text);
}
void setModelData(QWidget editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QLineEdit *lineEdit = static_cast <QLineEdit>(editor);
QString text = lineEdit->text();
model->setData(index, text, Qt::EditRole);
}
void updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
editor->setGeometry(option.rect);
}
};
然后在mainwindow.cpp中的构造函数里用到了 class UserIDDelegate
void MainWindow::set()
{
...
UserIDDelegate id;
routine_tableWidget->setItemDelegateForColumn(2,&id);
...
}
编译通过,程序正常跑,但用到这个功能的时候程序就崩溃了
这是啥情况,,断点调试又指向了 main()
整个人都不好了。。求大腿。。。