PDA

View Full Version : Problem with QTableView



habeas_corpse
11th November 2008, 13:25
Hello,
I am from brazil.

i am with a problem on the QTableView, when i put a model of the a Connection, not refresh...

code:

QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");

db.setHostName("localhost");
db.setDatabaseName("alan");
db.setUserName("postgres");
db.setPassword("351321");
bool ok = db.open();

QSqlTableModel *model = new QSqlTableModel(this,db);
model->setTable("tbproduto");
model->select();
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Codigo do Produto"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Produto"));

ui.Grade->setModel(model);
ui.Grade->show();

...

habeas_corpse
11th November 2008, 17:55
you understand?
how i can update the QTableView?

caduel
11th November 2008, 22:17
To be honest: no, I do not understand your problem.
Do you want the QSqlTableModel to track changes in the database so your view always show the "live" state and updates as modifications are made?

If yes:
bad luck. you will need to peridically (QTimer) call select() to refresh the contents of the model.
(As far as I know Qt does not support databases that push changes to clients. I might be wrong, though.)

Was that your question?