treeViewA と treeViewB という 2 つの異なる QTreeView があります。それぞれに独自の QStandardItemModel があります。treeViewA の 1 つの要素をクリックすると、信号がカスタム スロットに接続されます。treeViewB のモデルで同じ QStandardItem をそのすべての子で参照したいのですが、エラーQStandardItem::insertRows: Ignoring duplicate inserts of item 0x. になります。なぜですか? 一般的な考え方は、treeViewA にタイトルのみを表示するツリーが 2 つあり、ユーザーが 1 つのタイトルをクリックすると、そのすべてのプロパティ (QStandardItem 階層のタイトルの子) が treeViewB に表示されるため、ユーザーがプロパティ (テキスト) を変更したときに表示されます。 () in a QStandardItem) 変更は modelA にも保存されます。ご回答誠にありがとうございました!!!
MainClass::MainClass(){
modelA = new QStandardItemModel(); // Class QStandardItem*
modelB = new QStandardItemModel();
// Append a subclass of QStandardItem
modelA->invisibleRootItem()->appendRow((QStandardItem *)item);
//...
ui.treeViewA->setModel(modelA);
ui.treeViewA->setDragEnabled(true);
ui.treeViewA->show();
ui.treeViewB->setModel(modelB);
ui.treeViewB->setDragEnabled(false);
ui.treeViewB->show();
QObject::connect(ui.treeViewA, SIGNAL(clicked(const QModelIndex&)), this, SLOT(UpdateProperties(const QModelIndex&)));
}
void MainClass::UpdateProperties(const QModelIndex& index){
QStandardItem* item = planModel->itemFromIndex(index);
propertiesModel->invisibleRootItem()->appendRow(item); // At this point takes the duplication place although modelB is empty.
}