I have an QSqlTabelModel filled with data from three sql tables. When I press in customer browser button "Insert record" or "Change record", mthe update record window show, which contain several QLineEdit widgets. How do I save entered data into database? My exact question is, how to convert every QLineEdit.text() into corespoding record field and then save it?
const int INSERT_RECORD_AT_END=-1;
cDataRecord.setValue("SIFRA", m_pUpdateWindow->GetCustomerID()->text());
cDataRecord.setValue("DS", m_pUpdateWindow->GetTaxNumber()->text());
cDataRecord.setValue("PRIIMEK", m_pUpdateWindow->GetSurname()->text());
cDataRecord.setValue("IME", m_pUpdateWindow->GetName()->text());
//cDataRecord.setValue("ULICA", m_pUpdateWindow->GetStreetID()->text());
cDataRecord.setValue("STEVILKA_ULICE", m_pUpdateWindow->GetStreetNumber()->text());
cDataRecord.setValue("POSTA_STEVILKA", m_pUpdateWindow->GetZipCode()->text());
if(m_pTableModel->insertRecord(INSERT_RECORD_AT_END, cDataRecord))
{
{
qDebug() << m_pTableModel->query().lastQuery();
} // if
} // if
const int INSERT_RECORD_AT_END=-1;
QSqlRecord cDataRecord;
cDataRecord.setValue("SIFRA", m_pUpdateWindow->GetCustomerID()->text());
cDataRecord.setValue("DS", m_pUpdateWindow->GetTaxNumber()->text());
cDataRecord.setValue("PRIIMEK", m_pUpdateWindow->GetSurname()->text());
cDataRecord.setValue("IME", m_pUpdateWindow->GetName()->text());
//cDataRecord.setValue("ULICA", m_pUpdateWindow->GetStreetID()->text());
cDataRecord.setValue("STEVILKA_ULICE", m_pUpdateWindow->GetStreetNumber()->text());
cDataRecord.setValue("POSTA_STEVILKA", m_pUpdateWindow->GetZipCode()->text());
if(m_pTableModel->insertRecord(INSERT_RECORD_AT_END, cDataRecord))
{
QSqlError error=m_pTableModel->lastError();
if(error.type()!=QSqlError::NoError)
{
qDebug() << m_pTableModel->query().lastQuery();
} // if
} // if
To copy to clipboard, switch view to plain text mode
Is it maybe problem in insertRecord paramaters?
Bookmarks