C++ 如何在QTreeView中获取选择更改通知
我正试图弄明白这一点,似乎我必须使用QItemSelectionModel,但我找不到一个如何连接的示例 我已经在.h文件中定义了C++ 如何在QTreeView中获取选择更改通知,c++,qt,C++,Qt,我正试图弄明白这一点,似乎我必须使用QItemSelectionModel,但我找不到一个如何连接的示例 我已经在.h文件中定义了 QItemSelectionModel* selectionModel; 现在在视图的构造函数中,我设置: selectionModel = ui->treeView->selectionModel(); // the following line is not compiling! connect(ui->treeView->selec
QItemSelectionModel* selectionModel;
现在在视图的构造函数中,我设置:
selectionModel = ui->treeView->selectionModel();
// the following line is not compiling!
connect(ui->treeView->selectionModel(), SIGNAL( ui->treeView->selectionModel(const QModelIndex&, const QModelIndex &) ),
this, this->selectionChanged ( QItemSelection & sel, QItemSelection & desel) );
我以为会有预定义的插槽,但我找不到,所以我添加了这个(我找到的语法)
void MyDialog::selectionChanged(常量QItemSelection&selected,常量QItemSelection&deselected)
{
qDebug()该方法应按如下方式使用:
QObject::connect(sender, SIGNAL(signal_method), receiver, SLOT(slot_method));
所以你的情况应该是
connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT(mySelectionChanged(const QItemSelection&,const QItemSelection&)));
ui->treeView->selectionModel
不是一个信号,或者我是盲人吗?我知道,我从其他帖子中复制了这一行和其他大多数行:)谢谢它的工作,但是我如何从处理程序中的QItemSelection中获取QModelIndex?我在树中显示QFileSystemModel,需要获取新选择的文件名等最著名的文档QT文档的最新版本(5.x):。
connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT(mySelectionChanged(const QItemSelection&,const QItemSelection&)));