Results 1 to 2 of 2

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

  1. #1
    Join Date
    Jun 2009
    Location
    Bangalore
    Posts
    21
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How to pass FileInfo object instead of model index when Item selected in treeview ?

    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..

    Qt Code:
    1. connect(ui->treeView,SIGNAL(clicked(QModelIndex)),ui->widget, SLOT(UpdateDetails()));
    To copy to clipboard, switch view to plain text mode 

    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 ?

  2. The following user says thank you to prady for this useful post:


  3. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to pass FileInfo object instead of model index when Item selected in treeview

    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:
    Qt Code:
    1. ...
    2. connect(ui->treeView,SIGNAL(clicked(QModelIndex)), SLOT(handleClick(QModelIndex)));
    3. connect(this,SIGNAL(clickedFileInfo(QFileInfo)),ui->widget, SLOT(UpdateDetails(QFileInfo)));
    4. ...
    5. void MyWidget::handleClick(const QModelIndex &index)
    6. {
    7. //obtaining necessary FileInfo by QModelIndex or whatever...
    8. emit clickedFileInfo(obtainedFileInfo);
    9. }
    10. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. The following user says thank you to spirit for this useful post:


Similar Threads

  1. Replies: 1
    Last Post: 23rd December 2011, 08:30
  2. Replies: 1
    Last Post: 4th August 2011, 22:36
  3. Replies: 2
    Last Post: 4th December 2010, 08:09
  4. Connect button and pass QListView current index
    By been_1990 in forum Qt Programming
    Replies: 3
    Last Post: 30th November 2009, 16:20
  5. How to get parent of selected item in TreeView?
    By RavenS in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2009, 13:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.