Hi,
I'm calling primeInsert(int,QSqlRecord&) in order to set initial values for a QTableView/QSqlTableModel approach (not sure about this
).
void Dialog
::primeInsertImage(int row,
QSqlRecord &record
) {
record.setValue("id", generateNextId("object")); // To get the next free id
record.setValue("name", ui->fileNameLabel->text()); // To get a QString from a QLabel
QImage currentImage
= ui
->imageLabel
->pixmap
()->toImage
();
currentImage.save(&buffer, "PNG");
record.setValue("image", bytes); //To get the image previously loaded into a QLabel
}
void Dialog::primeInsertImage(int row, QSqlRecord &record)
{
record.setValue("id", generateNextId("object")); // To get the next free id
record.setValue("name", ui->fileNameLabel->text()); // To get a QString from a QLabel
QImage currentImage = ui->imageLabel->pixmap()->toImage();
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
currentImage.save(&buffer, "PNG");
record.setValue("image", bytes); //To get the image previously loaded into a QLabel
}
To copy to clipboard, switch view to plain text mode
The insert code is:
void Dialog::on_InsertRecord_clicked()
{
view->setFocus();
int row = model->rowCount();
model->insertRows(row,1);
QModelIndex index
= model
->index
(row, model
->fieldIndex
("id"));
view->setCurrentIndex(index);
view->edit(index);
}
void Dialog::on_InsertRecord_clicked()
{
view->setFocus();
int row = model->rowCount();
model->insertRows(row,1);
QModelIndex index = model->index(row, model->fieldIndex("id"));
view->setCurrentIndex(index);
view->edit(index);
}
To copy to clipboard, switch view to plain text mode
It works fine until i press enter (change record in the view).
Then i only get one fiel with data (The id).
The "name" and "image" fiels are NULL!
What could i be doing wrong?
Bookmarks