I have the following simple model using PyQt5, sqlite3 and python3.5.2.
我使用PyQt5、sqlite3和python3.5.2建立了以下简单的模型。
class choicesModel(QDialog):
def __init__(self, parent=None):
super(choicesModel, self).__init__()
query = QSqlQuery()
query.prepare("SELECT COUNT(*) FROM resident_choices")
query.exec_()
query.next()
dbrows = query.value(0)
print("rows in db: ", dbrows)
self.choicesModel = QSqlRelationalTableModel(self)
self.choicesModel.setEditStrategy(QSqlTableModel.OnManualSubmit)
self.choicesModel.setTable("resident_choices")
self.choicesModel.select()
rows = self.choicesModel.rowCount()
print("rows returned by model.select(): ", rows)
Executing the model produces the following output:
执行模型产生如下输出:
rows in db: 831
行db:831
rows after model.select(): 256
行model.select后():256
It appears that the initial select only populates the first 256 records. Is this an sqlite3 issue and if so how do I populate all records (the db only has about 850 records total). If not how can I force all records to be loaded?
似乎初始选择只填充前256条记录。这是一个sqlite3问题吗?如果是,我如何填充所有记录(db总共只有850条记录)。如果不是,我怎样才能强制加载所有记录?
The upshot is that using a proxymodel and proxy view does not initially show all records until I change the proxy filter condition - that is, I have to trigger the loading of the rest of the records.
其结果是,使用proxymodel和proxy视图最初不会显示所有记录,直到我更改了proxy filter条件——也就是说,我必须触发加载其余记录。
1 个解决方案
#1
1
The number of records is hard-coded as #define QSQL_PREFETCH 255
in the QSqlQueryModel
class. To override it, you will have to explicitly fetch all the rows yourself:
在QSqlQueryModel类中,记录的数量被硬编码为#define QSQL_PREFETCH 255。要重写它,您必须自己显式地获取所有行:
while self.choicesModel.canFetchMore():
self.choicesModel.fetchMore()
You will probably need to run code like this every time the model is updated, so it might be better to create your own sub-class and reimplement fetchMore.
每次模型更新时,您可能需要像这样运行代码,因此最好创建自己的子类并重新实现fetchMore。
#1
1
The number of records is hard-coded as #define QSQL_PREFETCH 255
in the QSqlQueryModel
class. To override it, you will have to explicitly fetch all the rows yourself:
在QSqlQueryModel类中,记录的数量被硬编码为#define QSQL_PREFETCH 255。要重写它,您必须自己显式地获取所有行:
while self.choicesModel.canFetchMore():
self.choicesModel.fetchMore()
You will probably need to run code like this every time the model is updated, so it might be better to create your own sub-class and reimplement fetchMore.
每次模型更新时,您可能需要像这样运行代码,因此最好创建自己的子类并重新实现fetchMore。