Hello everyone,
I'm working on a project and in the "add" feature I want to show a single row from a QSQlTableModel where the user can input data, on a "simple" database table, it worked like a charm, but when I wanted to replicate the same pattern on my project It didn't behave as expected, here's the scenario:
1- the program is launched, displaying a newly added row and hiding the previous ones
2- The user adds data and submits it through a button
3- A slot is called through the button to submit the newly added data, hide that row and display a new one
Here's the code of the slot:
{
model->submit();
int row = model->rowCount();
for (int i=0;i<row;i++)
ui->tabsave->hideRow(row); //hide the previous rows
model
->setData
(model
->index
(row,
5),
QTime::currentTime());
}
{
model->submit();
int row = model->rowCount();
for (int i=0;i<row;i++)
ui->tabsave->hideRow(row); //hide the previous rows
model->setData(model->index(row,5),QTime::currentTime());
}
To copy to clipboard, switch view to plain text mode
Here's the code regarding the formatting and display of the Model
ui->tabsave->setModel(model);
//model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
for (int i=16;i<20;i++)
{
ui->tabsave->hideColumn(i); //hiding some columns from the user
}
int row = model->rowCount();
for (int i=0;i<row;i++)
{
ui->tabsave->hideRow(i);
}
model->insertRow(row);
model
->setData
(model
->index
(row,
5),
QTime::currentTime());
ui->tabsave->setRowHeight(row,80);
////////////////SLOTS//////////////
QObject::connect(ui
->next_one,
SIGNAL(clicked
()),
this,
SLOT(added_next
()));
ui->tabsave->setModel(model);
//model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
for (int i=16;i<20;i++)
{
ui->tabsave->hideColumn(i); //hiding some columns from the user
}
int row = model->rowCount();
for (int i=0;i<row;i++)
{
ui->tabsave->hideRow(i);
}
model->insertRow(row);
model->setData(model->index(row,5),QTime::currentTime());
ui->tabsave->setRowHeight(row,80);
////////////////SLOTS//////////////
QObject::connect(ui->next_one,SIGNAL(clicked()),this,SLOT(added_next()));
To copy to clipboard, switch view to plain text mode
Voila, Hope I'll get some help around here. Thank you very much
Bookmarks