Results 1 to 8 of 8

Thread: Extracting path of a file sleected from a listbox

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2012
    Posts
    23
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Symbian S60
    Thanks
    9

    Default Extracting path of a file sleected from a listbox

    Hi

    I am trying to get the path of a selected file in a listbox.I am able to get the filename after selecting the file by the following code

    QModelIndex index = ui->treeView->currentIndex();
    ui->listWidget_2->addItem(index.data().toString());
    I want to get the full path of the selected file also, if there is any way please guide me.

    thanks

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Extracting path of a file sleected from a listbox

    We have no idea what is in the model you have, how you populated it, or what non-full file name you have so we cannot possibly give you concrete direction.

  3. #3
    Join Date
    Nov 2012
    Posts
    23
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Symbian S60
    Thanks
    9

    Default Re: Extracting path of a file sleected from a listbox

    Hi
    I am sorry for so less information, I have used the following code

    QFileSystemModel *model = new QFileSystemModel;
    model->setRootPath("/home/");
    ui->treeView->setModel(model);
    ui->treeView->setRootIndex(model->index("/home/"));

    So I have this file browser in my treeview and I am able to extract file names from this treeview to a listbox.
    I also want to have full path of the selected file from the tree view.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: Extracting path of a file sleected from a listbox

    Take a look at QFileInfo, you could use following
    Qt Code:
    1. QString QFileInfo::fileName () const
    2. QString QFileInfo::baseName () const;
    3. QString QFileInfo::completeBaseName () const
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. The following user says thank you to Santosh Reddy for this useful post:

    sargeslash (8th January 2013)

  6. #5
    Join Date
    Nov 2012
    Posts
    23
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Symbian S60
    Thanks
    9

    Default Re: Extracting path of a file sleected from a listbox

    Can I use the FileInfo for the selected index.data() from the treeView, since its not a file?

  7. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: Extracting path of a file sleected from a listbox

    Can I use the FileInfo for the selected index.data() from the treeView, since its not a file?
    Yes you can. QFileInfo can be used with the file name (QString()) which can be index.data().
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  8. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Extracting path of a file sleected from a listbox

    QAbstractItemView::currentIndex() in combination with QFileSystemModel::filePath() seems like the obvious option.

  9. The following user says thank you to ChrisW67 for this useful post:

    sargeslash (9th January 2013)

  10. #8
    Join Date
    Nov 2012
    Posts
    23
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Symbian S60
    Thanks
    9

    Default Re: Extracting path of a file sleected from a listbox

    QFileSystemModel::filePath()
    This worked for me, thank u all for the help

Similar Threads

  1. Displaying file name (not the entire file name path)
    By Ferric in forum Qt Programming
    Replies: 2
    Last Post: 15th November 2011, 04:23
  2. Specify file path for RCC
    By becrux in forum Qt Tools
    Replies: 0
    Last Post: 15th September 2010, 11:41
  3. Replies: 3
    Last Post: 11th August 2010, 13:47
  4. Extracting files from a zip file
    By Althor in forum Qt Programming
    Replies: 4
    Last Post: 11th March 2009, 10:39
  5. create self-extracting zip file thru Cygwin?
    By vonCZ in forum General Discussion
    Replies: 1
    Last Post: 22nd November 2007, 10:27

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
  •  
Qt is a trademark of The Qt Company.