#include <QtGui>
#include <QtSql>
int main(int argc, char *argv[])
{
db.setDatabaseName(":memory:");
if (db.open()) {
query.exec("CREATE TABLE " + str + "(\
id INTEGER PRIMARY KEY AUTOINCREMENT,\
title1 VARCHAR(255),\
title2 VARCHAR(255))");
model.setTable("title");
proxy.setSourceModel(&model);
proxy.setDynamicSortFilter(true);
proxy.setFilterKeyColumn(2);
rec5 = rec4 = rec3 = rec2 = rec1;
rec1.setValue("title1", "test1");
rec1.setValue("title2", "test11");
rec2.setValue("title1", "test2");
rec2.setValue("title2", "test22");
rec3.setValue("title1", "test3");
rec3.setValue("title2", "test33");
rec4.setValue("title1", "test4");
rec4.setValue("title2", "test44");
rec5.setValue("title1", "table5");
rec5.setValue("title2", "table55");
db.transaction();
model.insertRows(0, 10240);
for (int i = 0; i < 10240;)
{
if(i % 512 != 0)
model.setRecord(i++, rec1);
else
model.setRecord(i++, rec5);
model.setRecord(i++, rec2);
model.setRecord(i++, rec3);
model.setRecord(i++, rec4);
}
model.submitAll();
db.commit();
model.select();
view.setModel(&proxy);
view.resize(640, 480);
view.show();
le.show();
return app.exec();
}
else
{
return 1;
}
}
#include <QtGui>
#include <QtSql>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":memory:");
if (db.open()) {
QSqlQuery query;
QString str = "title";
query.exec("CREATE TABLE " + str + "(\
id INTEGER PRIMARY KEY AUTOINCREMENT,\
title1 VARCHAR(255),\
title2 VARCHAR(255))");
QSqlTableModel model;
model.setTable("title");
model.setEditStrategy(QSqlTableModel::OnManualSubmit);
QSortFilterProxyModel proxy;
proxy.setSourceModel(&model);
proxy.setDynamicSortFilter(true);
proxy.setFilterKeyColumn(2);
QSqlRecord rec1 = db.record("title");
QSqlRecord rec5, rec4, rec3, rec2;
rec5 = rec4 = rec3 = rec2 = rec1;
rec1.setValue("title1", "test1");
rec1.setValue("title2", "test11");
rec2.setValue("title1", "test2");
rec2.setValue("title2", "test22");
rec3.setValue("title1", "test3");
rec3.setValue("title2", "test33");
rec4.setValue("title1", "test4");
rec4.setValue("title2", "test44");
rec5.setValue("title1", "table5");
rec5.setValue("title2", "table55");
db.transaction();
model.insertRows(0, 10240);
for (int i = 0; i < 10240;)
{
if(i % 512 != 0)
model.setRecord(i++, rec1);
else
model.setRecord(i++, rec5);
model.setRecord(i++, rec2);
model.setRecord(i++, rec3);
model.setRecord(i++, rec4);
}
model.submitAll();
db.commit();
model.select();
QTableView view;
view.setModel(&proxy);
view.resize(640, 480);
view.show();
QLineEdit le;
le.show();
QObject::connect(&le, SIGNAL(textChanged(QString)), &proxy, SLOT(setFilterFixedString(QString)));
return app.exec();
}
else
{
return 1;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks