[Interest] QSqlTableModel couldn't insert new record.

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


I’ve found the problem... The problem solved with:

QSqlRecord r = d->model->record();

From: igor.mironchik at gmail.com 
Sent: Friday, February 14, 2014 2:07 PM
To: interest at qt-project.org 
Subject: QSqlTableModel couldn't insert new record.

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/ef000152/attachment.html>


More information about the Interest mailing list