【发布时间】:2016-09-01 03:32:35
【问题描述】:
我有一个带有两个QListViews 的接口,其中左边决定了右边显示的内容:
要更新右侧的列表,我有以下功能:
void CodePlug::handleSelectionChanged()
{
QModelIndex portIndex = ui->listPorts->currentIndex();
QString portItemText = portIndex.data(Qt::DisplayRole).toString();
ui->listPlugs->setModel(ListModelFromMap(plugs[portItemText]));
currentPort = portItemText;
qDebug(currentPort.toStdString().data());
}
它在这里连接到 selectionChanged 信号:
CodePlug::CodePlug(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::CodePlug)
{
ui->setupUi(this);
ui->listPorts->setModel(ListModelFromMap(ports));
QModelIndex portIndex = ui->listPlugs->currentIndex();
QString portItemText = portIndex.data(Qt::DisplayRole).toString();
ui->listPlugs->setModel(ListModelFromMap(plugs[portItemText]));
connect(ui->listPorts->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(handleSelectionChanged()));
}
但是,通过键盘或鼠标更改所选项目永远不会触发handleSelectionChanged()。它不会产生任何错误,它只是不做任何事情。谁能告诉我为什么?
【问题讨论】: