• QSqlQueryModel使用小结


    基本用法

    用QSqlQueryModel::setQuery设置sql查询。

    第一种重载方法要求query必须是活动的,即query已经执行过。示例:

    QSqlQueryModel的动态更新

    很遗憾,QSqlQueryModel无法自动更新。因为它使用的QSqlQuery在设置前就已经执行,无法再次执行。所以,需要手动更新QSqlQueryModel的数据,比如重新设置一个刚执行过没开始遍历的QSqlQuery。在查询时间不长的情况下可以用QTimer定时刷新数据。

    QSqlQueryModel与QListView结合

    Qt的Model/View模型使用起来很方便,同一个模型可以和不同的视图继承。QSqlQueryModel最适合QTableView表格视图,不过也可以用QListView列表视图。使用QListView::setModelColumn(int column) 设置列表视图显示的列即可。QListView的属性modelColumn文档如下:

    modelColumn : int
    This property holds the column in the model that is visible.

    By default, this property contains 0, indicating that the first column in the model will be shown.

    Access functions:

    int modelColumn () const
    void setModelColumn ( int column )

  • 相关阅读:
    Vue 项目中 ESlint 配置
    ajax、axios、fetch 对比
    vue 中 axios 使用
    NodeJS 多版本管理(NVM)
    axio 请求中参数是数组
    Python 图片文字识别
    .NET 使用 VLC 播放视频
    Python 常见问题
    SpringBoot(4) SpringBoot热部署
    SpringBoot(3) 文件上传和访问
  • 原文地址:https://www.cnblogs.com/alleyonline/p/4781314.html
Copyright © 2020-2023  润新知