A
A
Artem Filimonov2017-04-03 09:06:17
Qt
Artem Filimonov, 2017-04-03 09:06:17

How to connect a signal to select a model element with its own slot?

treeView = new QTreeView();
  treeView->header()->hide();
  treeView->setModel(treeCtrl);
  QItemSelectionModel* _select;
  _select = new QItemSelectionModel(treeCtrl);
  treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
  treeView->setContextMenuPolicy(Qt::CustomContextMenu);

  connect(treeView, &QWidget::customContextMenuRequested, this, &MainForm::treeContextMenu);
  connect(_select, &QItemSelectionModel::selectionChanged,
    this, &MainForm::treeSelectionChanged);

and my slot:
void MainForm::treeSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
{
  qDebug() << "selectionChanged";
  QModelIndex index = selected.indexes().at(0);

  propCtrl = new StatPropCtrl(&index);
}

Does not go into the slot, there is a breakpoint, but alas.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2017-04-03
@gbg

connect returns true?

A
Artem Filimonov, 2017-04-03
@Nvek

apparently not, since it doesn’t enter the function at all, the
main thing is in the slot where the first connection enters the breakpoint, and the second one doesn’t
, it doesn’t work either

connect(treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), SLOT(treeSelectionChanged(QModelIndex, QModelIndex)));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question