PDA

View Full Version : How to pass FileInfo object instead of model index when Item selected in treeview ?



prady
7th August 2012, 12:33
I have one treeView and one widget in my main UI, which is promoted to myTreeView and myWidget respectively. Now I connecting these two widgets by..


connect(ui->treeView,SIGNAL(clicked(QModelIndex)),ui->widget, SLOT(UpdateDetails()));

myTreeView uses FileSystemModel, so here I want to pass FileInfo object of the selected item to myWidget::UpdateDetails slot, instead of model index. Could some one tell me how to do this ?

spirit
7th August 2012, 12:41
Well, there are two options:
1st - subclass QTreeView and add a signal with necessary signature or
2nd - catch "clicked" signal and get necessary FileInfo and then emit a signal with this value. Something like this:


...
connect(ui->treeView,SIGNAL(clicked(QModelIndex)), SLOT(handleClick(QModelIndex)));
connect(this,SIGNAL(clickedFileInfo(QFileInfo)),ui->widget, SLOT(UpdateDetails(QFileInfo)));
...
void MyWidget::handleClick(const QModelIndex &index)
{
//obtaining necessary FileInfo by QModelIndex or whatever...
emit clickedFileInfo(obtainedFileInfo);
}
...