慢滚动与QTableView在其他比较
Slow scrolling with QTableView on other comp
我目前正在使用Qt开发一个数据库浏览应用程序;c++。数据库在我们的内部网络中。我在工作。在Win7 32位上编译,Qt 4.7.3 + qodbc驱动。我的项目目标是使我们的用户可以使用这些数据,即使他们正在旅行,在这种情况下使用VPN。连接非常慢(我的意思是:非常慢)。
我有一个QTableView填充2k个结果。我只需要win7的支持,它在我们公司的电脑上运行得很好,这些电脑都在网络上。但在某些电脑上运行很慢,比如在QTableView上滚动。这似乎只有在使用VPN时才会发生。我填充QTableView的方法是使用setQuery()所以我想知道是否有一些网络的东西执行查询后执行?如果是这样,问题是什么呢?我在谷歌和Qt文档中找不到任何答案。
编辑:问题似乎直接来自QSqlQuery。我已经实现了以下模型作为尝试,以避免无用的查询(是的,它是快速和肮脏的):class SqlAsyncModel : public QSqlQueryModel
{
public:
explicit SqlAsyncModel(QObject *parent = 0) : QSqlQueryModel(parent) {}
SqlAsyncModel(QSqlQueryModelPrivate &dd, QObject *parent)
: QSqlQueryModel(dd, parent) {}
void queryChange() { _currRow = 0; qu = this->query(); qu.last(); }
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole)
{
int r = index.row(); int c = index.column();
if(!index.isValid() || role & ~Qt::DisplayRole || r < 0 || c < 0)
return QVariant();
while (_currRow < r)
if (!nextValue()) goto ret;
while (_currRow > r)
if (prevValue()) goto ret;
ret: return (qu.record().value(c));
// Returns value or QVariant() if invalid QSqlRecord
}
private:
inline bool nextValue() { _currRow++; return qu.next(); }
inline bool prevValue() { _currRow--; return qu.previous(); }
int _currRow;
QSqlQuery qu;
这仍然给我相同的行为。注意:我也使用:
while (mySqlAsyncModel->canFetchMore())
mySqlAsyncModel->fetchMore();
所以问题来自qodbresult行为。我下载了Qt的源代码,并编辑了odbc驱动程序。对于那些对它感兴趣的人,你需要改变QODBCResult::data(int)的行为,至少QODBCResult::fetch(int)(如果你真的想要一些干净的东西,也许QODBCResult::fetchprevious/next/last/first)函数。
我个人添加了一个QList缓冲区,在请求时存储我的行。它几乎与Qt相同的行为(因为它不缓存所有内容,但只缓存请求的行)。我的应用程序占用高达38-40 mb的内存22k行/55列的文本和浮动缓存
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 为什么比较运算符如此快速
- 对于BTreeMap和其他依赖于Ord的东西,是否有等效于C++比较器对象?
- 这种比较是否不一致(或者存在其他问题)?
- 将 64 位整数中的每个其他位与 32 位整数进行比较
- 如何仅在C 中比较其他字段对
- 如何将多个变量与其他if语句进行比较
- 为什么在浮点比较中,最后一个小数位数为5的浮点值能给出正确的输出,而在其他情况下却不是
- c++ 输入一个数字来确定其他数字,然后比较它们
- 动态C++与其他语言的比较 - 在不知道类型的情况下无法在对象上调用方法
- C++ 如果其他链和嵌套用于变量比较
- 可视化C++编译器与其他C++编译器的比较
- 将二进制文件内容保存在字符串中,以便能够对其进行 md5 并在以后与其他文件进行比较
- 我如何将自己的排序算法与其他算法进行比较
- 将类向量的两个函数返回值与其他类向量元素函数进行比较
- 慢滚动与QTableView在其他比较
- 如何比较同一对象的两个向量并获得其他元素
- 最准确和正确的方式来比较两个大的windows 8.1注册表文件(c++ / c#或任何其他)