PDA

View Full Version : Qt Sql :how can update data in different tables when i use qTableModel



hqh
3rd January 2014, 16:31
Hi ,everyone! i am using qt sql to do a small software,but i encountered some difficulty;
i don't know how to update data in other table when i update one ;
eg: table A( name text , address text,primary key(name) );
table B(id integer,name references A(name),tel integer);

when i update field name in table A ,how can i update field name in table B, the point is that i use the QSqlTableModel to handle the data updating,
i find a signal called 'beforeUpdate' in QSqlTableModel,but it seems that the signal is emitted before update data in dataBase not before update data in model, so i come to look for help,my english is not good,thx!

ChrisW67
3rd January 2014, 21:08
What do you mean by "update the field name"?

If two views are sharing the same QSqlTableModel then changes to the data in the table in one view will be visible in the other.

hqh
4th January 2014, 02:49
sorry,i didn't make it clear. i mean using "update tableName set field=?"statement when i say update field name. and the 'table' is a sql table not a tableView , but the point is that i have only use a tableView and i want to update data cascade, and that means when i change one field which is the foreign key of another table,it is expected that the foreign key in another table also makes change. in the SQL manage ,there is something called "cascade",it's similar to this! anyway ,thanks!