The following code is untested but it will give you the basics
in.setCodec("UTF-8");
while (!line.isNull())
{
// just guessing that you have an autoincrement field on column 0
for (int field=1 ; field<rec.count() ; ++field)
{
if (field==4) continue; // was ignored on save
rec.setValue(field, line); // line is a Qstring. maybe you should change it to something else
}
model->insertRecord(-1, rec);
line = in.readLine();
}
// what is the model's edit strategy?
// if it is QSqlTableModel::OnManualSubmit
// call model->submitAll() and check for errors
if (!model->submitAll())
qDebug()<<"error: "<<model->lastError().text();
QTextStream in(&file);
in.setCodec("UTF-8");
QString line=in.readLine();
while (!line.isNull())
{
QSqlRecord rec=model->record();
// just guessing that you have an autoincrement field on column 0
rec.setValue(0, QVariant());
for (int field=1 ; field<rec.count() ; ++field)
{
if (field==4) continue; // was ignored on save
rec.setValue(field, line); // line is a Qstring. maybe you should change it to something else
}
model->insertRecord(-1, rec);
line = in.readLine();
}
// what is the model's edit strategy?
// if it is QSqlTableModel::OnManualSubmit
// call model->submitAll() and check for errors
if (!model->submitAll())
qDebug()<<"error: "<<model->lastError().text();
To copy to clipboard, switch view to plain text mode
Bookmarks