QAbstractItemModel
(Model
と言う)を継承するツリーモデルクラスと、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();
}
です。なぜそれが機能しないのですか?