Results 1 to 2 of 2

Thread: Help with QDir model

  1. #1
    Join Date
    Jun 2007
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Help with QDir model

    Hi,
    I am new in Qt and I i have a QTreeWidget and QTreeModel and I dont know how to get the selected filename when I click on the file in Tree Widget. Please send code If you can. (I really dont understand the model/view architecture.) Thanks a lot.
    Qt Code:
    1. tree = new QTreeView(dockWidget);
    2. QDirModel *model = new QDirModel(tree);
    3. tree->setModel(model);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Help with QDir model

    Well, you can connect to for example QAbstractItemView::activated(QModelIndex) or QAbstractItemView::clicked(QModelIndex) and use the index passed as parameter, or you can get the current index via QAbstractItemView::currentIndex().

    Once you have the index at hand, you can do
    Qt Code:
    1. QModelIndex index = ...
    2. if (index.isValid())
    3. {
    4. QString filePath = dirModel->filePath(index);
    5. // or
    6. QFileInfo fileInfo = dirModel->fileInfo(index);
    7. ...
    8. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 20:17
  2. Coin3d + Qt: SIGLNALs and SLOTs
    By vonCZ in forum Newbie
    Replies: 26
    Last Post: 15th May 2009, 07:34
  3. Help with Model View
    By weepdoo in forum Qt Programming
    Replies: 13
    Last Post: 12th October 2007, 10:32
  4. Model Choices review/questions
    By ucntcme in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2007, 21:57
  5. How to explicitely delete a QDir?
    By alan in forum Newbie
    Replies: 2
    Last Post: 13th February 2006, 17:48

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.