c++ - 我如何在 Qt 中使用 itemFromIndex

标签 c++ qt

我的表单中有一个 listWidget,我决定使用它

on_listView_clicked(const QModelIndex &index)

信号。

在插槽实现中,我想获取每次被点击的项目,因为我有项目索引,所以我考虑使用

QListWidgetItem * curItm = ui->listView->itemFromIndex(index);

但是我得到了错误:

'itemFromIndex' is a protected member of 'QListWidget'

我怎样才能使用这个特定的功能?

最佳答案

如果不派生 QListWidget,则不能使用该特定函数。

最简单的解决方法可能就是简单地使用

QListWidgetItem* curItm = ui->listView->item(index->row());

关于c++ - 我如何在 Qt 中使用 itemFromIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29742254/

相关文章:

c++ - 如何将 sysroot 与 autoconf 一起使用?

c++ - 了解 C++ 中的动态对象 ("new")

c++ - spoj 上的抗印迹系统

C++ Qt 5.10 Cross compiling for Raspberry PI 3 此应用程序无法启动,因为它无法在 "xcb"中找到或加载 Qt 平台插件 ""

c++ - 为什么在抛出 'std::bad_alloc' 实例后调用终止?

c++ - iMAC 上的 Qt5.11.2、QSqlDatabase 和 MariaDB

c++ - 如何找出 QQuickItem 派生类对象何时初始化?

c++ - 主要使用 C++ 绑定(bind)时如何提供 AffinityFunction.BackupFilter

c++ - 可变参数计数函数

qt - 滚动 QML 网格