Doesn't seem normal to me:
#include <QtGui>
#include <QtSql>
#include <QDebug>
#include "connection.h"
{
Q_OBJECT
public:
public slots:
{ qDebug() << "dataChanged" << topLeft << bottomRight; }
};
int main(int argc, char *argv[])
{
if (!createConnection())
return 1;
model.setTable("person");
model.select();
MyTableView t1;
t1.setWindowTitle("View 1");
t1.setModel(&model);
SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)) ,
&t1,
SLOT(dataChanged(const QModelIndex&,const QModelIndex&)));
MyTableView t2;
t2.setWindowTitle("View 2");
t2.setModel(&model);
t1.show();
t2.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
#include <QtSql>
#include <QDebug>
#include "connection.h"
class MyTableView: public QTableView
{
Q_OBJECT
public:
MyTableView(): QTableView() {}
public slots:
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{ qDebug() << "dataChanged" << topLeft << bottomRight; }
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
if (!createConnection())
return 1;
QSqlTableModel model;
model.setTable("person");
model.setEditStrategy(QSqlTableModel::OnFieldChange);
model.select();
MyTableView t1;
t1.setWindowTitle("View 1");
t1.setModel(&model);
QObject::connect(&model,
SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)) ,
&t1,
SLOT(dataChanged(const QModelIndex&,const QModelIndex&)));
MyTableView t2;
t2.setWindowTitle("View 2");
t2.setModel(&model);
t1.show();
t2.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Changes in View 2 correctly update View 1 using dataChanged()
Bookmarks