PDA

View Full Version : QDiaglog, getting the error: ..."was not declared in this scope"



juliano.gomes
2nd June 2015, 20:35
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)
{
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);
}
}
}


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 (http://doc.qt.io/qt-5/qdialog.html), but i can't solve this. Can any one give some light?

thanks,
Juliano

stampede
2nd June 2015, 21:02
Basic C++ - you need to include the header with "NewContact" class declaration.