PDA

View Full Version : QSqlTableModel & datachanged()



noValue
20th November 2010, 13:59
Hi everyone,

I have a QSqlTableModel with an "OnFieldChange" editStrategy and use the
"dataChanged" signal to tidy up my gui.

This works fine when I change the data in my model programmatically.
But if I change the data through a connected QTableView the event gets never fired.

2 Questions:
1. Is this normal behavior?
2. And if its, is there any other signal I could connect to (maybe something from the view...) ?

thanx for any help

Joerg

franz
22nd November 2010, 11:26
Had a look at the sql/tablemodel example (http://doc.trolltech.com/latest/sql-tablemodel.html) and if not, does it do what you need?

noValue
23rd November 2010, 00:47
Hello franz,

thanx for responding.


Had a look at the sql/tablemodel example (http://doc.trolltech.com/latest/sql-tablemodel.html) and if not, does it do what you need?

Yeah, I know the example, and basicly it does the same as I'am doing with my model here, but with
one significant difference. It's on an "OnManualSubmit" editStrategie, means data gets only saved when you do an "submitAll()" and if you do that a "dataChanged" signal gets fired.

What I want to do is to work whit a "OnFieldChange" editStrategy, and when I do that, the mentioned Signal is missing.

Right now, I would already be grateful if somebody could confirm that this behavior is normal (even though I didn't discover something like that in the documentation) and I simply misunderstood the concept, or this is irregular and worth more debugging time.

Any guess?

regards

Joerg

ChrisW67
23rd November 2010, 01:22
Doesn't seem normal to me:


#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::OnFieldChang e);
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"

Changes in View 2 correctly update View 1 using dataChanged()

noValue
24th November 2010, 01:23
Thanks ChrisW67,

that was what I needed to know, if this is working for you, then I
will go one step further, trying to get this up and running over here.
I'll post back if I make any progress.

regards

Joerg

noValue
26th November 2010, 00:26
Hi all,

right now I think this all complies too http://bugreports.qt.nokia.com/browse/QTBUG-1945

This would fit for me cause I'am limited to update QT for I'am using QTJambi.

I'am testing this out shortly,

Bye

Joerg