【问题标题】:How to connect QTableView selection changed Signal如何连接 QTableView 选择改变的信号
【发布时间】:2021-05-30 05:02:06
【问题描述】:

我在我的 GUI 中插入了一个 QTableView 并设置了 selectionMode = SingleSelectionselectionBehavior = SelectRows

我想通过更改所选行将我的插槽连接到一个信号(选择更改或另一个信号)。

请看我的代码:

connect(ui->tableView->selectionModel(),
    SIGNAL( selectionChanged(const QItemSelection&,
    const QItemSelection&)), this ,SLOT(myslot()));

我收到一条错误消息:

QObject::connect: 无法连接 (null)::selectionChanged(const QItemSelection&, const QItemSelection&) 到 Info::myslot

【问题讨论】:

  • 请编辑您的问题以澄清"My Code doesn't work" 的含义。顺便说一句,如果可能的话,您可能应该转到Qt5 signal/slot syntax

标签: c++ qt


【解决方案1】:

没有看到minimal, reproducible example,很难确定问题的真正根源,但消息...

QObject::connect: Cannot connect (null)::selectionChanged(const QItemSelection&, const QItemSelection&) to Info::myslot

建议表达式...

ui->tableView->selectionModel()

计算为空指针。在建立连接之前,您需要确保您的 UI 已设置好

【讨论】:

  • 在尝试使用 selectionModel 而不设置可见模型时,该错误很典型,即 selectionModel 为空,直到视图设置为可见模型:所以解决方案应该是:@987654324 @connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &FooClass::myslot);
猜你喜欢
  • 2023-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-26
  • 1970-01-01
  • 1970-01-01
  • 2019-03-17
相关资源
最近更新 更多