Not 100% elegant ... but it works like this!
void CidadaoDialog
::antesDeInserirCidadao(QSqlRecord ®isto
) {
int lin, col;
lin = vistaCidadao->currentIndex().row();
col = 0;
conteudoDaChave
= modeloCidadao
->index
(lin, col,
QModelIndex()).
data(Qt
::EditRole);
comando = "SELECT * FROM Cidadao WHERE idCidadao = " + conteudoDaChave.toString()+";";
query.prepare(comando);
query.exec();
if(query.next())
{
msg.setText("Chave duplicada(duplicate key)!");
msg.setInformativeText(query.lastQuery());
msg.exec();
modeloCidadao->select();
}
}
void CidadaoDialog::antesDeInserirCidadao(QSqlRecord ®isto)
{
QSqlQuery query;
QString comando;
int lin, col;
QVariant conteudoDaChave;
lin = vistaCidadao->currentIndex().row();
col = 0;
conteudoDaChave = modeloCidadao->index(lin, col, QModelIndex()).data(Qt::EditRole);
comando = "SELECT * FROM Cidadao WHERE idCidadao = " + conteudoDaChave.toString()+";";
query.prepare(comando);
query.exec();
if(query.next())
{
QMessageBox msg;
msg.setText("Chave duplicada(duplicate key)!");
msg.setInformativeText(query.lastQuery());
msg.exec();
modeloCidadao->select();
}
}
To copy to clipboard, switch view to plain text mode
What i was looking for is in line 9.
Thanks
Bookmarks