Results 1 to 8 of 8

Thread: Qt 5 Drop Custom Files outside my app

  1. #1
    Join Date
    Jan 2015
    Posts
    15
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Qt 5 Drop Custom Files outside my app

    Hi All,

    I'm not able to do this simple action.
    I have an application that interact with an usb device and, in a special tab, i show to the user a listview that present a special directory of that device.
    At some point, i want to let the user drag a file(s) from the device(from the listview) to the desktop(or wherever he wants).

    I tryed to use the DelayedEncoding example http://doc.qt.digia.com/4.6/dragandd...dencoding.html from QT 4.6 but, for my custom file, seems not work. when i drop the file to desktop nothing happen.

    The function:
    Qt Code:
    1. void SourceWidget::createData(const QString &mimeType)
    2. {
    3. if ( mimeType != "application/x-delayedencoding" )
    4. return;
    5.  
    6. mimeData->setData( "application/x-delayedencoding", imageData );
    7. }
    To copy to clipboard, switch view to plain text mode 
    is never called from the MimeData function
    Qt Code:
    1. QVariant retrieveData(const QString &mimetype, QVariant::Type type) const;
    To copy to clipboard, switch view to plain text mode 
    I think the problem is the creation of the mime data object, but i'm not able to understand what i have to do for insert information like mime data and mime type for my custom files.

    Thanks in advace, for any help or suggestion.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt 5 Drop Custom Files outside my app

    Your posting is kind of missing the essential information, your QMimeData subclass.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2015
    Posts
    15
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Qt 5 Drop Custom Files outside my app

    Hi, thanks for the fast reply.

    The problem is that i'm not sure how to do that..
    QMimeData subclass is the same of the example,
    Qt Code:
    1. #include <QtGui>
    2. #include "mimedata.h"
    3.  
    4. MimeData::MimeData()
    5. : QMimeData(){
    6. }
    7.  
    8. QStringList MimeData::formats() const{
    9. return QMimeData::formats() << "application/x-delayedencoding";
    10. }
    11.  
    12. QVariant MimeData::retrieveData(const QString &mimeType, QVariant::Type type) const
    13. {
    14. emit dataRequested(mimeType);
    15.  
    16. return QMimeData::retrieveData(mimeType, type);
    17. }
    To copy to clipboard, switch view to plain text mode 
    with the only difference is
    Qt Code:
    1. return QMimeData::formats() << "application/x-delayedencoding";
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt 5 Drop Custom Files outside my app

    Are you sure the drop target understands that MIME type?

    Also, why is there a signal in the retrieve function?

    Cheers,
    _

  5. #5
    Join Date
    Jan 2015
    Posts
    15
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Qt 5 Drop Custom Files outside my app

    This is a good point. But how can i check that?

    The signal is there to create the mimedata only when a drop target is found.

    You can see from the example.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt 5 Drop Custom Files outside my app

    Quote Originally Posted by papercut87 View Post
    This is a good point. But how can i check that?
    Well, I guess it would have called retrieveData(), but you can try with a standard QMimeData and just put some sample data into it right away.

    You can also test the general mechanism by creating a small "drop target" application.

    Quote Originally Posted by papercut87 View Post
    The signal is there to create the mimedata only when a drop target is found.

    You can see from the example.
    Very strange design, especially since the signal won't given the recipient any indication where to put the data.

    Cheers,
    _

  7. #7
    Join Date
    Jan 2015
    Posts
    15
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Qt 5 Drop Custom Files outside my app

    Quote Originally Posted by anda_skoa View Post
    Very strange design, especially since the signal won't given the recipient any indication where to put the data._
    It's weird, but is not my design..

    Quote Originally Posted by anda_skoa View Post
    You can also test the general mechanism by creating a small "drop target" application._
    I had already try all example in the QT directory about drag & drop. However all examples are created to work with widget that are moved/dropped inside the same app(another instance of the same app.)

    The example Drop Site show me that the mime type of my files is "text/uri-list" however if i use this mime type, i get the "block" symbol on drop target.

    So there is no Documentation about how to export custom file?

  8. #8
    Join Date
    Jan 2015
    Posts
    15
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Qt 5 Drop Custom Files outside my app

    Thanks for your time and help man.

    It's about two days that i'm looking for a solution.. (google and search function on the forum)
    NOW i found another thread http://www.qtcentre.org/threads/5784...open-directory where you solved this problem.

    So, thanks so much again!

Similar Threads

  1. Assign custom actions to Drag And Drop?
    By QphiuchuS in forum Qt Quick
    Replies: 0
    Last Post: 14th December 2014, 11:27
  2. how to make drag and drop possible in custom widget
    By psarangi in forum Qt Programming
    Replies: 0
    Last Post: 23rd February 2014, 16:36
  3. I wanna drag and drop some files into QTreeView
    By guri in forum Qt Programming
    Replies: 4
    Last Post: 28th September 2011, 10:13
  4. Drag and drop files
    By MTK358 in forum Qt Programming
    Replies: 14
    Last Post: 9th September 2010, 23:27
  5. Replies: 1
    Last Post: 2nd August 2010, 21:16

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.