hello buddies,
I'm trying to implement a QDialog to update data retrieved from a QTableView, so I'm doing this:
#include <QDialog>
void MainWindow
::on_tvMain_doubleClicked(const QModelIndex &index
) {
db.setDatabaseName("agenda");
db.open();
model->setTable("departamentos");
model->select();
if (sample.row() >= 0 ) {
NewContact dlg(this);
dlg.setNome(rec.value("NOME").toString());
dlg.setSigla(rec.value("SIGLA").toString());
if (dlg.
exec() == QDialog::Accepted) { rec.setValue("NOME",dlg.nome());
rec.setValue("SIGLA",dlg.sigla());
model->setRecord(sample.row(),rec);
}
}
}
#include <QDialog>
void MainWindow::on_tvMain_doubleClicked(const QModelIndex &index)
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("agenda");
db.open();
QSqlTableModel *model = new QSqlTableModel(this, db);
model->setTable("departamentos");
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->select();
QSqlRecord rec = model->record();
QModelIndex sample = ui->tvMain->currentIndex();
if (sample.row() >= 0 ) {
QSqlRecord rec = model->record(sample.row());
NewContact dlg(this);
dlg.setNome(rec.value("NOME").toString());
dlg.setSigla(rec.value("SIGLA").toString());
if (dlg.exec() == QDialog::Accepted) {
rec.setValue("NOME",dlg.nome());
rec.setValue("SIGLA",dlg.sigla());
model->setRecord(sample.row(),rec);
}
}
}
To copy to clipboard, switch view to plain text mode
But i'm getting the following error in line 17:
/home/elementaryos/Projetos/Agenda/Agenda/mainwindow.cpp:78: error: 'NewContact' was not declared in this scope
NewContact dlg(this);
^
/home/elementaryos/Projetos/Agenda/Agenda/mainwindow.cpp:78: error: expected ';' before 'dlg'
NewContact dlg(this);
^
/home/elementaryos/Projetos/Agenda/Agenda/mainwindow.cpp:79: error: 'dlg' was not declared in this scope
dlg.setName(rec.value("name").toString());
^
I've read various threads in this forum, on internet and in qt documentation, but i can't solve this. Can any one give some light?
thanks,
Juliano
Bookmarks