[Interest] QSqlTableModel couldn't insert new record.

igor.mironchik at gmail.com igor.mironchik at gmail.com
Fri Feb 14 13:07:11 CET 2014


Hi.

I have the next SQLite table:

QSqlQuery table( QLatin1String(	"CREATE TABLE IF NOT EXISTS contacts ( "		"marked INTEGER, contact TEXT, "		"type TEXT, comment TEXT )" ) );
And the next QSqlTableModel:
model = new QSqlTableModel( w, db );model->setTable( QLatin1String( "contacts" ) );model->setEditStrategy( QSqlTableModel::OnFieldChange );model->select();
I’m trying to insert new record to the table with:
QSqlRecord r;r.setValue( 0, 0 );r.setValue( 1, QString() );r.setValue( 2, QString() );r.setValue( 3, QString() );if( !d->model->insertRecord( -1, r ) )	QMessageBox::critical( 0, tr( "Database Error..." ),		tr( "Couldn't insert new record into database.\n%1" )			.arg( d->model->lastError().isValid() ?				d->model->lastError().text() : QString() ) );
But I received the error: “No Fields to update”. And new record wasn’t inserted. I’ve tried to call d->model->insertRow( –1 ) but this failed too without any error.
What am I doing wrong? Or may be it’s a bug?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140214/5c818b9c/attachment.html>


More information about the Interest mailing list