2017-06-13 9 views
0

QAbstractItemModelModelと言う)を継承するツリーモデルクラスと、QSortFilterProxyModelを継承する2つのフィルタプロキシモデルがあります。Qtモデル/ビュー:プロキシモデルのsetRootIndexが失敗する

m_groupFilter->setSourceModel(m_model); 
m_parameterFilter->setSourceModel(m_model); 

及びこれらのフィルタはUI上の2つのQTreeView秒に設定されています:どちらのプロキシモデルは、同じモデルのインスタンスに設定されている

ui->treeViewGroups->setModel(m_groupFilter); 
ui->treeViewParameters->setModel(m_parameterFilter); 

を今、私はに、2番目のビューのsetRootIndex()にしたいです最初のものから選択された項目。私はこれを行う上での信号を接続するので:上記のコード

QModelIndex actualIndex = m_groupFilter->mapToSource(index); 
QModelIndex mappedIndex = m_parameterFilter->mapFromSource(actualIndex); 
qDebug() << mappedIndex.isValid(); 
qDebug() << ui->treeViewParameters->model(); 
qDebug() << mappedIndex.model(); 
ui->treeViewParameters->setRootIndex(mappedIndex); 

は、この出力と警告して失敗します。

true 
ConfigurationParameterFilterModel(0x43d190) 
ConfigurationParameterFilterModel(0x43d190) 
QAbstractItemView::setRootIndex failed : index must be from the currently set model 
QAbstractItemView::setRootIndex failed : index must be from the currently set model 

私はこれが唯一の入力setRootIndexのインデックスとオブジェクトの時にモデルを起こることがわかりますsetRootIndexをオンにするか、異なるか(ここでは該当しません)、またはインデックスが無効です(ここでは該当しません)。以下はQt source code that generates the warning

void QAbstractItemView::setRootIndex(const QModelIndex &index) 
{ 
    Q_D(QAbstractItemView); 
    if (Q_UNLIKELY(index.isValid() && index.model() != d->model)) { 
     qWarning("QAbstractItemView::setRootIndex failed : index must be from the currently set model"); 
     return; 
    } 
    d->root = index; 
    d->doDelayedItemsLayout(); 
    d->updateGeometry(); 
} 

です。なぜそれが機能しないのですか?

答えて

0

あなたが表示したコードはOkです。 Qt Creatorの標準テンプレートプロジェクトにコピーしました。それは適切に働いた。あなたのプロキシモデルの実装とsetRootIndexの他の場所を確認してください。

関連する問題