Results 1 to 3 of 3

Thread: QDirModel and QListView > problem getting filepath

  1. #1
    Join Date
    Feb 2008
    Posts
    50
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDirModel and QListView > problem getting filepath

    Hello guys. QT Newb here. Having a bad day...

    First will show some code:

    Qt Code:
    1. void ImCo::createDockWindows()
    2. {
    3. dock = new QDockWidget(tr("Available Frames"), this);
    4. dock->setAllowedAreas(Qt::RightDockWidgetArea);
    5.  
    6. dirmodel = new QDirModel;
    7. dirmodel->setFilter(QDir::Files | QDir::NoSymLinks);
    8. dirmodel->setSorting(QDir::Name);
    9. listView = new QListView();;
    10. listView->setModel(dirmodel);
    11. listView->setRootIndex(dirmodel->index(QDir::currentPath() + "/frames"));
    12. dock->setWidget(listView);
    13. connect(listView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(test(const QModelIndex &)));
    14. addDockWidget(Qt::RightDockWidgetArea, dock);
    15. opt->addAction(dock->toggleViewAction());
    16. }
    17.  
    18. void ImCo::test(const QModelIndex &index){
    19. int r = index.row();
    20. // I click on one of the files showed on the QListView, and i need the path to the clicked file !!!
    21. ww.some_func(path_to_the_file, var1, var2...);//this func needs the path to the file so it can be opened from other class
    22. }
    To copy to clipboard, switch view to plain text mode 
    I`m forming a dock window which is showing the contents of a directory underneath my executable. When i click on a file on the dock QListView i want to call a function which has a parameter with a path to the file i clicked on the listView. So my question is: how to get the path to the file i clicked for the function ImCo::test. I only get the number of the item trough index.row. I don`t know how to get the filepath from the dirmodel. Hope i explained it well. Thanx in advance.
    Last edited by sadjoker; 8th April 2008 at 00:32.

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDirModel and QListView > problem getting filepath

    I would say - read the docs. There're enough functions where you can retrieve informations about the current file from the model index.

  3. #3
    Join Date
    Feb 2008
    Posts
    50
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDirModel and QListView > problem getting filepath

    Wow, how can i miss those... starting now on fresh mind and it seems so easy lol
    I think i needed a rest the last night.
    Thank you

Similar Threads

  1. QListView and QDirModel
    By BTe in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2008, 16:36
  2. QListView trouble accepting drops
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 6th September 2007, 19:49
  3. QDialog / QListView problem
    By harakiri in forum Qt Programming
    Replies: 1
    Last Post: 10th July 2007, 18:31
  4. QDirModel
    By L.Marvell in forum Newbie
    Replies: 2
    Last Post: 5th June 2007, 14:47

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.