gpt4 book ai didi

c++ - QFileSystemModel - 增量更新/抢先更新

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:39:21 26 4
gpt4 key购买 nike

来自 Qt 文档:

QFileSystemModel will not fetch any files or directories until setRootPath() is called. This will prevent any unnecessary querying on the file system until that point such as listing the drives on Windows.

Unlike QDirModel(obsolete), QFileSystemModel uses a separate thread to populate itself so it will not cause the main thread to hang as the file system is being queried. Calls to rowCount() will return 0 until the model populates a directory. QFileSystemModel keeps a cache with file information. The cache is automatically kept up to date using the QFileSystemWatcher.

我将 QTreeView 与使用可勾选框的子类 QFileSystemModel 一起使用。
如果我在项目在树中展开之前调用 QFileSystemModel::rowCount(index),我将收到“0”,无论是否有任何子目录或文件。然而,一旦它被展开,正确的行数将在再次调用时给出。

我想如果你调用 QFileSystemModel::setRootPath() 这将从指定的文件路径获取数据,但它似乎在我调用 之前“执行得不够快”(缓存未更新) QFileSystemModel::rowCount 在我下面的代码中。

// Whenever a checkbox in the TreeView is clicked
bool MyModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
if (role == Qt::CheckStateRole)
{
if (value == Qt::Checked)
{
setRootPath(this->filePath(index));
checklist.insert(index);
set_children(index);
}
else
{
checklist.remove(index);
unchecklist->insert(index);
}
emit dataChanged(index, index);
return true;
}

return QFileSystemModel::setData(index, value, role);
}

// Counts how many items/children the node has (i.e. file/folders)
void MyModel::set_children(const QModelIndex& index)
{
int row = this->rowCount(index);

qDebug() << QString::number(row);

}

有没有办法在我尝试计算该文件夹中包含多少项目之前先发制人地收集子文件夹信息?

谢谢

最佳答案

QFileSystemModel 发出 directoryLoaded(const QString &path)信号,当收集线程完成加载目录时。

关于c++ - QFileSystemModel - 增量更新/抢先更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7283102/

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