Hi,
I have a problem editing or inserting rows in a QTableView + QSqlQueryModel.
Here my code:
MainDialog
::MainDialog(QWidget *parent
){
...
scoopsModel->setQuery("SELECT numero,pagina,sottotitolo FROM elenco_scoop WHERE id_gioco="
+ articlesComboBox->itemData(articlesComboBox->currentIndex()).toString()
+ " ORDER BY numero");
scoopsModel->setHeaderData(0, Qt::Horizontal, tr("Numero"));
scoopsModel->setHeaderData(1, Qt::Horizontal, tr("Pagina"));
scoopsModel->setHeaderData(2, Qt::Horizontal, tr("Sottotitolo"));
scoopsTableView->setModel(scoopsModel);
scoopsTableView->show();
connect(scoopAddButton, SIGNAL(clicked()), this, SLOT(addScoop()));
...
}
MainDialog::MainDialog(QWidget *parent)
:QDialog(parent)
{
...
scoopsModel = new QSqlQueryModel;
scoopsModel->setQuery("SELECT numero,pagina,sottotitolo FROM elenco_scoop WHERE id_gioco="
+ articlesComboBox->itemData(articlesComboBox->currentIndex()).toString()
+ " ORDER BY numero");
scoopsModel->setHeaderData(0, Qt::Horizontal, tr("Numero"));
scoopsModel->setHeaderData(1, Qt::Horizontal, tr("Pagina"));
scoopsModel->setHeaderData(2, Qt::Horizontal, tr("Sottotitolo"));
scoopsTableView->setModel(scoopsModel);
scoopsTableView->show();
connect(scoopAddButton, SIGNAL(clicked()), this, SLOT(addScoop()));
...
}
To copy to clipboard, switch view to plain text mode
void MainDialog::addScoop()
{
}
void MainDialog::addScoop()
{
((QSqlQueryModel*)scoopsTableView->model())->insertRows(((QSqlQueryModel*)scoopsTableView->model())->rowCount(), 1);
}
To copy to clipboard, switch view to plain text mode
1) First problem: if I double click a cell of a row it doesn't switch in edit mode;
2) Second problem: when clicking scoopAddButton no new row is inserted; insertRows(..) returns false.
Where is the error?
Thanks
Bookmarks