Nefastious
19th October 2009, 18:34
Hi there guys!
I'm having a small problem here, whenever i try to insert a QSqlRecord into a QSqlTableModel, I know that a new row is inserted (QTableView shows that) but data simply isn't displayed in the view (the fields remain blank). Here is the code:
in mainw.cpp
//this makes the adddialog SLOT to instantiate an "Add" dialog
void mainwindow::adddialogslot() {
adddialog *add = new adddialog;
add->show();
if (add->Accepted) {
model->insertRecord(-1,add->record);
}
}
in adddialog.cpp
void adddialog::allowinput() {
if (lineEdit_name->text().isEmpty() || lineEdit_surname->text().isEmpty()
|| lineEdit_phone->text().isEmpty() || lineEdit_phone1->text().isEmpty()
|| lineEdit_phone2->text().isEmpty() || lineEdit_phone3->text().isEmpty()
|| lineEdit_address->text().isEmpty() || lineEdit_year->text().isEmpty()
|| lineEdit_insurance->text().isEmpty() || lineEdit_HS->text().isEmpty()
|| lineEdit_diseases->text().isEmpty() || lineEdit_treat->text().isEmpty()
|| lineEdit_comp->text().isEmpty() || comboBox_day->currentText().isEmpty()
|| comboBox_month->currentText().isEmpty() || !(radioButton_M->isChecked() || radioButton_F->isChecked()) ) {
QMessageBox::information(this, tr("Add Patient"), tr("Please fill in all of the required fields"));
}
else {
record.setValue("name", lineEdit_name->text());
record.setValue("surname", lineEdit_surname->text());
if (radioButton_M->isChecked()) {
record.setValue("gender", "M");
}
else {
record.setValue("gender", "F");
}
record.setValue("birth date", comboBox_day->currentText() + "/" + comboBox_month->currentText() +"/"+ lineEdit_year->text());
record.setValue("address", lineEdit_address->text());
record.setValue("phone number", lineEdit_phone->text() + lineEdit_phone1->text() + lineEdit_phone2->text() + lineEdit_phone3->text());
record.setValue("insurance number", lineEdit_insurance->text());
record.setValue("health system", lineEdit_HS->text());
record.setValue("diseases", lineEdit_diseases->text());
record.setValue("treatments", lineEdit_treat->text());
record.setValue("complications", lineEdit_comp->text());
}
}
What am I doing wrong? Any code samples would be greatly appreciated.
Thanks in advance,
Nefastious :confused:
I'm having a small problem here, whenever i try to insert a QSqlRecord into a QSqlTableModel, I know that a new row is inserted (QTableView shows that) but data simply isn't displayed in the view (the fields remain blank). Here is the code:
in mainw.cpp
//this makes the adddialog SLOT to instantiate an "Add" dialog
void mainwindow::adddialogslot() {
adddialog *add = new adddialog;
add->show();
if (add->Accepted) {
model->insertRecord(-1,add->record);
}
}
in adddialog.cpp
void adddialog::allowinput() {
if (lineEdit_name->text().isEmpty() || lineEdit_surname->text().isEmpty()
|| lineEdit_phone->text().isEmpty() || lineEdit_phone1->text().isEmpty()
|| lineEdit_phone2->text().isEmpty() || lineEdit_phone3->text().isEmpty()
|| lineEdit_address->text().isEmpty() || lineEdit_year->text().isEmpty()
|| lineEdit_insurance->text().isEmpty() || lineEdit_HS->text().isEmpty()
|| lineEdit_diseases->text().isEmpty() || lineEdit_treat->text().isEmpty()
|| lineEdit_comp->text().isEmpty() || comboBox_day->currentText().isEmpty()
|| comboBox_month->currentText().isEmpty() || !(radioButton_M->isChecked() || radioButton_F->isChecked()) ) {
QMessageBox::information(this, tr("Add Patient"), tr("Please fill in all of the required fields"));
}
else {
record.setValue("name", lineEdit_name->text());
record.setValue("surname", lineEdit_surname->text());
if (radioButton_M->isChecked()) {
record.setValue("gender", "M");
}
else {
record.setValue("gender", "F");
}
record.setValue("birth date", comboBox_day->currentText() + "/" + comboBox_month->currentText() +"/"+ lineEdit_year->text());
record.setValue("address", lineEdit_address->text());
record.setValue("phone number", lineEdit_phone->text() + lineEdit_phone1->text() + lineEdit_phone2->text() + lineEdit_phone3->text());
record.setValue("insurance number", lineEdit_insurance->text());
record.setValue("health system", lineEdit_HS->text());
record.setValue("diseases", lineEdit_diseases->text());
record.setValue("treatments", lineEdit_treat->text());
record.setValue("complications", lineEdit_comp->text());
}
}
What am I doing wrong? Any code samples would be greatly appreciated.
Thanks in advance,
Nefastious :confused: