[Qt-interest] QDataWidgetMapper, QSqlTableModel and AutoSubmit
Wilhelm
wilhelm.meier at fh-kl.de
Tue Oct 12 08:06:33 CEST 2010
Am 11.10.2010 18:07, schrieb Wilhelm:
> Hi,
>
> I found a strange behaviuor with QDataWidgetMapper:
>
> The first time I edit a field value with the widget (QLineEdit) the
> column is mapped to, the model gets updated (e.g. the QTableView gets
> this new value). When I modifiy the field a second time, nothing happens!
>
Update:
This works only if I add:
connect(tv->selectionModel(),
SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
mapper, SLOT(setCurrentModelIndex(QModelIndex)));
> And further: if I edit the field value in the QTableView, the mapped
> widget gets not updated.
>
Update:
This works only if I add:
connect(tm, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
mapper, SLOT(setCurrentModelIndex(QModelIndex)));
Well, reading the docu of QDataWidgetMapper carefully, the example below
should work *without* the above
connections.
Is this by design or a bug?
> Any hints?
> -
>
> Widget::Widget(QWidget *parent)
> : QWidget(parent) {
>
> QVBoxLayout* l = new QVBoxLayout(this);
>
> QTableView* tv = new QTableView(this);
> l->addWidget(tv);
>
> QSqlTableModel* tm = new QSqlTableModel(this);
> tm->setEditStrategy(QSqlTableModel::OnFieldChange);
>
> tm->setTable("vorgang");
> tm->setHeaderData(0, Qt::Horizontal, tr("id"));
> tm->setHeaderData(1, Qt::Horizontal, tr("Start"));
> tm->setHeaderData(2, Qt::Horizontal, tr("End"));
>
> if (!tm->select()) {
> qDebug() << "select nok";
> }
> tv->setModel(tm);
> tv->resizeColumnsToContents();
> tv->setItemDelegateForColumn(1, new Delegate(this));
>
> l->addWidget(new QLabel("Vorgang"));
> QLineEdit* le = new QLineEdit(this);
> l->addWidget(le);
>
> QDataWidgetMapper* mapper = new QDataWidgetMapper(this);
> mapper->setModel(tm);
> mapper->addMapping(le, tm->fieldIndex("beschreibung"));
> mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
> mapper->toFirst();
> }
>
>
>
--
Wilhelm
More information about the Qt-interest-old
mailing list