2011-09-02 3 views
3

:QFileSystemModel - 증분 업데이트/선제 갱신 Qt의 문서에서

이 QFileSystemModel이 setRootPath 될 때까지 파일 또는 디렉터리를 가져 오지 않습니다()가 호출된다. 이렇게하면 Windows에 드라이브를 나열하는 것과 같은 시점까지 파일 시스템에서 불필요한 쿼리를 방지 할 수 있습니다.

QDirModel (구식)과 달리 QFileSystemModel은 별도의 스레드를 사용하여 파일 시스템을 쿼리 할 때 주 스레드가 정지하지 않도록 자체 스레드를 채 웁니다. 모델이 디렉토리를 채울 때까지 rowCount()를 호출하면 0이 반환됩니다. QFileSystemModel은 파일 정보가있는 캐시를 유지합니다. 캐시는 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); 

} 

내가 그 폴더에 포함 된 항목 수 계산하기 전에 하위 폴더 정보를 수집 예방 적 사전 수있는 방법이 있나요? 스레드가 디렉토리를 로딩 완료 수집 할 때

감사

답변