_inputfileModel
是QStandardItemModel
類型的指針,我想使用它的成員函數children()
讓孩子們的物品。但在隨後的代碼, int childrenNum = _inputfileModel->children().size();
childrenNum
的結果不是1,但0。但是當我使用hasChildren()
,返回值是真實的。誰能解釋爲什麼?並且功能children()
返回給孩子或所有的孩子?爲什麼QStandardItemModel的成員函數的孩子()。大小()返回0,而功能hasChildren()返回true?
void InputTree::addTreeNode(TreeNode &node){
QStringList inputImgList = node.picturePathList;
int num = inputImgList.size();
if(num < 1){ return ;}
QStandardItem *fatherItem = new QStandardItem;
fatherItem->setIcon(node.fatherIcon);
fatherItem->setText(node.fatherNodeName);
fatherItem->setData(FOLDER,ItemTypeRole);
for(int i = 0; i < num; ++i)
{
QStandardItem *pictureItem = new QStandardItem;
pictureItem->setText(node.imageNodeName.at(i));
pictureItem->setIcon(node.imgIcon);
pictureItem->setData(PICTURE,ItemTypeRole);
fatherItem->appendRow(pictureItem);
}
_inputfileModel->appendRow(fatherItem);
bool has_child = false;
has_child = _inputfileModel->hasChildren();
int childrenNum = _inputfileModel->children().size();
}