有什么方法可以确定我正在查看的 QTreeWidgetItem
是否是顶级的?如果项目是顶级(无父项),当我尝试获取父项的文本时,程序会崩溃。
最佳答案
引用 the documentation :
The main difference between top-level items and those in lower levels of the tree is that a top-level item has no parent(). This information can be used to tell the difference between items, and is useful to know when inserting and removing items from the tree.
if (!node.parent()) {
// top-level item
}
关于c++ - 查找 QTreeWidgetItem 是否为顶级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2320846/