Here it is:
It looks like the model can't hold more than 256 records. Something strange is going on 
Run it first as is and them comment out
mSqlModel.setEditStrategy(QSqlTableModel::OnManual Submit); and the submitAll line
and see the difference.
#include <QApplication>
#include <QTranslator>
#include <QMessageBox>
#include <QSqlError>
#include <QSqlRecord>
#include <iostream>
#include <QtDebug>
#include <QSqlQuery>
#include <QSqlTableModel>
int main(int argc, char *argv[])
{
// Set up the database connection
database.setDatabaseName(":memory:");
if(!database.open())
{
QObject::tr("Could not open database; driver said: %1, database said: %2") .arg(database.lastError().driverText())
.arg( database.lastError().databaseText()));
return -1;
}
if(!query.exec("CREATE TABLE test ("
"id INTEGER PRIMARY KEY,"
"str VARCHAR(100))"))
{
qDebug() << "Could not create table; driver said: "
<< database.lastError().driverText() << ", database said: "
<< database.lastError().databaseText();
return -2;
}
mSqlModel.setTable("test");
mSqlModel.select();
std::cout << "ROWS=" << mSqlModel.rowCount() << std::endl;
for(int row=0;row<5000;row++)
{
record.
setValue("str",
QVariant("123abc"));
mSqlModel.insertRecord(-1,record);
}
std::cout << "ROWS=" << mSqlModel.rowCount() << std::endl;
if(!mSqlModel.submitAll())
std::cout << "Can't add row=" << std::endl;
std::cout << "ROWS=" << mSqlModel.rowCount() << std::endl;
return -1;
}
#include <QApplication>
#include <QTranslator>
#include <QMessageBox>
#include <QSqlError>
#include <QSqlRecord>
#include <iostream>
#include <QtDebug>
#include <QSqlQuery>
#include <QSqlTableModel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Set up the database connection
QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
database.setDatabaseName(":memory:");
if(!database.open())
{
QMessageBox::critical(0, QObject::tr("Error"),
QObject::tr("Could not open database; driver said: %1, database said: %2")
.arg(database.lastError().driverText())
.arg( database.lastError().databaseText()));
return -1;
}
QSqlTableModel mSqlModel;
QSqlQuery query;
if(!query.exec("CREATE TABLE test ("
"id INTEGER PRIMARY KEY,"
"str VARCHAR(100))"))
{
qDebug() << "Could not create table; driver said: "
<< database.lastError().driverText() << ", database said: "
<< database.lastError().databaseText();
return -2;
}
mSqlModel.setTable("test");
mSqlModel.setEditStrategy(QSqlTableModel::OnManualSubmit);
mSqlModel.select();
std::cout << "ROWS=" << mSqlModel.rowCount() << std::endl;
for(int row=0;row<5000;row++)
{
QSqlRecord record = mSqlModel.record();
record.setValue("str",QVariant("123abc"));
mSqlModel.insertRecord(-1,record);
}
std::cout << "ROWS=" << mSqlModel.rowCount() << std::endl;
if(!mSqlModel.submitAll())
std::cout << "Can't add row=" << std::endl;
std::cout << "ROWS=" << mSqlModel.rowCount() << std::endl;
return -1;
}
To copy to clipboard, switch view to plain text mode
TEMPLATE = app
TARGET +=
DEPENDPATH += .
INCLUDEPATH += .
QT += xml sql network
# Input RESOURCES +=
HEADERS += \
SOURCES += \
main.cpp \
FORMS += \
TEMPLATE = app
TARGET +=
DEPENDPATH += .
INCLUDEPATH += .
QT += xml sql network
# Input RESOURCES +=
HEADERS += \
SOURCES += \
main.cpp \
FORMS += \
To copy to clipboard, switch view to plain text mode
Bookmarks