PDA

View Full Version : Autoupdate QTableView



cyupa
31st January 2010, 22:39
How can I manage to somehow autoupdate a QTableView that returns data from a MySQL Table trough a QSqlQueryModel.
I add the data into the database from two QlineEdit.


//casuta dreapta jos
QLabel *added_table_label = new QLabel(tr("Lista websiteuri"));
QTableView *added_sites = new QTableView;
QSqlQueryModel *inputlista = db.show_table_sites();
added_sites->setFixedWidth(500);
added_sites->setModel(inputlista);
added_sites->setColumnWidth(0,245);
added_sites->setColumnWidth(1,245);
added_sites->show();
QVBoxLayout *lista_websiteuri = new QVBoxLayout;
lista_websiteuri->addWidget(added_table_label);
lista_websiteuri->addWidget(added_sites);


void window::addsite()
{
web_address = this->website_add->text();
email_address = this->email_add->text();
string adresaw=web_address.toStdString();
const char *argument_site=adresaw.c_str();
string adresae=email_address.toStdString();
const char *argument_email=adresae.c_str();
db.addtolist(contorsite, argument_site, argument_email);
website_add->clear();
email_add->clear();
contorsite++;
}

ChrisW67
1st February 2010, 08:33
QSqlQueryModel is read-only. If it were a QSqlTableModel you could simply use QSqlTableModel::insertRows() and the view would update for free. If you need to use QSqlQueryModel then you should look at the Query Model Example (http://qt.nokia.com/doc/4.6/sql-querymodel.html) for ways to make a read-only model editable.