PDA

View Full Version : QtTableView update



cpuinthebrain
24th June 2015, 20:35
I have QWidget with tableView and QDialog with textEdit and button

In the QDialog i enter a data and when click on the button it adds a new record in the QSqlQueryModel (i'm using SQLite).
I add the data correctly, but i need to update the tableView in order to display the new record.I read in the internet that it should automatically update it, but it doesn't.

What i make is call a signal when the new record is inserted in the model.Than i connect it to a slot in the QWidget:



Partners::Partners(QWidget *parent) :
QWidget(parent),
ui(new Ui::Partners)
{
ui->setupUi(this);

QSqlQueryModel *model = new QSqlQueryModel;

model->setQuery("SELECT Name, City, Bulstat FROM partners");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Име"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Град"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("ЕИК:"));

ui->tableView_partners->setModel(model);
ui->tableView_partners->setColumnWidth(0,299);
ui->tableView_partners->setColumnWidth(1,225);
ui->tableView_partners->setColumnWidth(2,225);
ui->tableView_partners->horizontalHeader()->sectionResizeMode(QHeaderView::Interactive);
ui->tableView_partners->horizontalHeader()->setStretchLastSection(true);

}

Partners::~Partners()
{
delete ui;
}


void Partners::updatePartnersTable()
{
//the code which update the table should be here
qDebug() << "updated";
}