QT - QListView - 当前选择/当前已更改 未发出
QT - QListView - currentSelection/currentChanged is not emitted
我无法在QListView中选择更改时获取信号发射。
到目前为止,我已经尝试了多种方法,但只有那些在没有调试器抱怨的情况下连接了:
// Approach 1
QStandardItemModel *standardModel = new QStandardItemModel(ui->instr_list);
ui->instr_list->setModel(standardModel);
QItemSelectionModel *selectionModel = ui->instr_list->selectionModel();
connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT (update_bin_instr(QModelIndex, QModelIndex)));
// Approach 2
QStandardItemModel *standardModel = new QStandardItemModel(ui->instr_list);
ui->instr_list->setModel(standardModel);
QItemSelectionModel *selectionModel = ui->instr_list->selectionModel();
connect(selectionModel, SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT (update_bin_instr(QItemSelection, QItemSelection)));
instr_list是QListView
信号应该发出,但没有任何反应。有人可以指出(对你们中的一些人(我做错了什么的明显事情吗?:-)
如果我正确理解了您的问题,您希望每次更改qlistview中的选择时都会触发update_bin_instr。
在主窗口中,我添加了
private slots:
void Update(const QModelIndex ¤t, const QModelIndex &previous);
private:
QStringListModel *m_Model;
QItemSelectionModel *selectionModel;
在主窗口构造函数中。
m_Model = new QStringListModel();
QStringList list;
list << "a" << "b" << "c";
m_Model->setStringList(list);
ui->listView->setModel(m_Model);
selectionModel = ui->listView->selectionModel();
connect(selectionModel, &QItemSelectionModel::currentChanged, this, &MainWindow::Update);
}
每次我更改选择更新时都会被调用。
void MainWindow::Update(const QModelIndex ¤t, const QModelIndex &previous)
{
qDebug() << "changed" << "current" << current.row() << "previous" << previous.row();
}
相关文章:
- 如何使用默认参数等选择模板专业化
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- 选择要调用的构造函数
- C++选择排序算法中的逻辑错误
- QTreeView幻灯片多选后无法使用单击选择
- 无法获取菜单选择以运行函数.C++
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 在C++中,如何通过几种类型从元组中选择多个元素
- 讨论 - 创建矩阵时的数组与向量的向量 - 什么是最实用的选择
- 对可变参数使用声明.如何选择正确的功能
- 选择选举获胜者的程序
- Qt:当QListView获得新条目时,如何更新QStringList
- 如何选择在 csv 文件中输出的位置
- 根据用户回答声明"Players"。用户选择玩家数量。播放器是结构体
- QT - QListView - 当前选择/当前已更改 未发出
- QListView:当从顶部删除项目时,如何自动滚动视图并保持视图中正确项目的当前选择
- 如何在选择多个项目时清除QListView的选择
- QListView的默认选择模型的所有权
- QListView改变MultiSelection选择模式的行为
- QListView具有复选框选择行为的项目