gpt4 book ai didi

performance - QCombobox 与具有大型模型的 QSqlQueryModel 一起工作非常慢

转载 作者:行者123 更新时间:2023-12-05 03:12:43 24 4
gpt4 key购买 nike

我很少有组合框,其中包含大约 10 万行或更多行的非常挖掘的数据集。我尝试使用 QStandardItemModel - 如果预加载模型,工作速度足够快,如果在单独的线程中执行,模型加载也需要几秒钟。尝试使用 QSqlQueryModel 组合框而不使用线程来提高性能,但体验它的工作速度比 QStandardItemModel 慢得多(在我们的项目中 QSqlQueryModel 使用如此多的线程工作得非常快数据与 QTreeView 例如)。这里可能是什么问题?有没有办法加速组合框,一些参数?

附言Qt 文档建议 QComboBox::AdjustToMinimumContentsLengthWithIcon 不会加快速度:使用此类组合的对话开始时间过长,并在 10-20 秒后退出。 AdjustToMinimumContentsLength 工作得更快一点,但无论如何延迟都太长了。

最佳答案

找到解决方案。第一个想法是找到哪种模型可以更快地工作,例如 QStringListModel 替换 QStandardItemModelQSqlQueryModel。但是似乎它们的工作速度几乎相同。第二,我在 Qt 文档中发现组合框默认使用 QStandardItemModel 来存储项目,QListView 子类显示弹出列表。您可以直接访问模型和 View (使用 model()view())。这对我来说很奇怪,因为我知道 QTreeView 可以很好地处理更大的数据量,而且更简单的 QListView 也继承自 QAbstractItemView 应该可以做到这一点以及。我开始深入研究 QListView 并在其中找到了解决问题的属性:现在组合框会立即打开大量数据。编写了静态函数来调整所有此类组合(带有解释的注释来自 Qt 文档):

void ComboboxTools::tweak(QComboBox *combo)
{
// For performance reasons use this policy on large models
// or AdjustToMinimumContentsLengthWithIcon
combo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);

QListView *view = (QListView *)combo->view();
// Improving Performance: It is possible to give the view hints
// about the data it is handling in order to improve its performance
// when displaying large numbers of items. One approach that can be taken
// for views that are intended to display items with equal sizes
// is to set the uniformItemSizes property to true.
view->setUniformItemSizes(true);
// This property holds the layout mode for the items. When the mode is Batched,
// the items are laid out in batches of batchSize items, while processing events.
// This makes it possible to instantly view and interact with the visible items
// while the rest are being laid out.
view->setLayoutMode(QListView::Batched);
// batchSize : int
// This property holds the number of items laid out in each batch
// if layoutMode is set to Batched. The default value is 100.
}

关于performance - QCombobox 与具有大型模型的 QSqlQueryModel 一起工作非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32750885/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com