PDA

View Full Version : QSqlRelationalDelegate



pippo42
30th April 2010, 16:02
Hello,

I have derived a class from QSqlRelationalDelegate and redefined the following functions.



class ItemDelegate : public QSqlRelationalDelegate{
Q_OBJECT
public:
ItemDelegate(QObject *parent=0);
~ItemDelegate();
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void addRelatedModel(RelatedModel *);
};


When I try to use it with a QDataWidgetMapper, I obtain a segmentation fault.



dataWidgetMapper->setItemDelegate(itemDelegate);


I have debugged and found out that the function createEditor is not called but setEditorData is, The segmentation fault occurs when it tries to use the editor that has not been initialised.

What I am doing wrong?

Thank you for your help!

pippo42
2nd May 2010, 12:05
And if I attach the item delegate to the table view



tableView->setItemDelegate(itemDelegate)


the createEditor function is called before the setEditorData and there is no longer a segmentation fault but the tableView behaves in a psychedelic way. If I edit something, the contents the cells are in a certain way mixed up. If I edit a cell, the cell where I was before takes the previous value of the cell I just modified.

I guess I must be doing something wrong but I did exactly the same thing as in the documentation.

Thanks!...