Results 1 to 3 of 3

Thread: Qt get absolute directory path from Qtreeview

  1. #1
    Join Date
    Jul 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Qt get absolute directory path from Qtreeview

    Hi QT,

    I have a Qtreeview for exploring local drives content and i am dropping a file from another Qlistview to the Qtreeview. Now i want to get absolute path of that directory in the Qtreeview where i am dropping the directory/file from Qlistview.
    For example I have a directory named "example" in the D drive then i want to get "D:/example". Right now i am able to call drop function and getting name of that destination directory where i am dropping the source directory/file. I need this because i have to call a hand written function to copy the source dir/file to that destination path using some command.

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt get absolute directory path from Qtreeview

    The models viewed by the QListView and QTreeView must agree on a format (more precisely, a MIME type) representing the data being dragged and dropped.

    For instance, you could choose the standard text/uri-list MIME type, and represent the files begin dragged as the list of their URLs. QMimeData::setUrls() will let you encode a list of QUrl as MIME data.

    Then, follow the documentation that explains how to set up the source and target models and views so that they share this MIME type to drag and drop files:
    http://doc.qt.io/qt-4.8/model-view-programming.html#using-drag-and-drop-with-item-views
    The source model will need custom implementations of QAbstractItemModel::mimeTypes() and QAbstractItemModel::mimeData(). The target model will need custom implementations of QAbstractItemModel::mimeTypes(), QAbstractItemModel::dropMimeData(), and maybe QAbstractItemModel::canDropMimeData().

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt get absolute directory path from Qtreeview

    Quote Originally Posted by ashish18 View Post
    I have a Qtreeview for exploring local drives content and i am dropping a file from another Qlistview to the Qtreeview. Now i want to get absolute path of that directory in the Qtreeview where i am dropping the directory/file from Qlistview.
    You forgot to mention what kind of model you are using.

    For a QFileSystemModel that would be trivial, but if you have a custom model, then you'll need to implement support for this information there.

    Cheers,
    _

Similar Threads

  1. QDir::entryList() get absolute path
    By Aji Enrico in forum Qt Programming
    Replies: 3
    Last Post: 23rd April 2011, 04:26
  2. qmake absolute vs relative LIBS path
    By TheShow in forum Newbie
    Replies: 7
    Last Post: 12th October 2010, 14:40
  3. Absolute Path to users "Program Files" on Windows
    By MisterIKS in forum Qt Programming
    Replies: 6
    Last Post: 5th June 2010, 09:40
  4. Replies: 8
    Last Post: 17th October 2009, 08:10
  5. getting absolute file path of Qt resources
    By dvmorris in forum Qt Programming
    Replies: 6
    Last Post: 18th April 2007, 02:56

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.