c++ - 查找 QTreeWidgetItem 是否为顶级

标签 c++ qt

有什么方法可以确定我正在查看的 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/

相关文章:

c++ - 为什么我无法将 QWebsocket::error SIGNAL 连接到 lambda 或具有相同签名的任何其他 SLOT 类型? QT5.9

c++ - 在 std::list 上 push_back 或删除时出现段错误

c++ - C/C++ 检查是否在 unsigned int 中设置了第 31 位

c++ - 服务器端

c++ - 如果单击标题 View ,如何按 TableView 中的列对数据进行排序

c++ - 尝试用 Qt 打开文件对话框

c++ - 我可以在构建新模板参数时使用一个可变模板参数吗?

c++ - 我的 char 数组显示的最后几个字符很短。 C++

c++ - 如何在 Raspberry Pi 上拥有类似智能手机/平板电脑的 GUI?

qt - 在 QML 中绘制弧/圆扇区?