慢滚动与QTableView在其他比较

Slow scrolling with QTableView on other comp

本文关键字:其他 比较 QTableView 滚动      更新时间:2023-10-16

我目前正在使用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列的文本和浮动缓存