PDA

View Full Version : Qt 5 Drop Custom Files outside my app



papercut87
20th April 2015, 10:42
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/draganddrop-delayedencoding.html from QT 4.6 but, for my custom file, seems not work. when i drop the file to desktop nothing happen.

The function:

void SourceWidget::createData(const QString &mimeType)
{
if ( mimeType != "application/x-delayedencoding" )
return;

mimeData->setData( "application/x-delayedencoding", imageData );
}

is never called from the MimeData function
QVariant retrieveData(const QString &mimetype, QVariant::Type type) const;
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.

anda_skoa
20th April 2015, 10:59
Your posting is kind of missing the essential information, your QMimeData subclass.

Cheers,
_

papercut87
20th April 2015, 11:14
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,


#include <QtGui>
#include "mimedata.h"

MimeData::MimeData()
: QMimeData(){
}

QStringList MimeData::formats() const{
return QMimeData::formats() << "application/x-delayedencoding";
}

QVariant MimeData::retrieveData(const QString &mimeType, QVariant::Type type) const
{
emit dataRequested(mimeType);

return QMimeData::retrieveData(mimeType, type);
}
with the only difference is
return QMimeData::formats() << "application/x-delayedencoding";

anda_skoa
20th April 2015, 11:27
Are you sure the drop target understands that MIME type?

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

Cheers,
_

papercut87
20th April 2015, 11:42
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.

anda_skoa
20th April 2015, 12:42
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.



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,
_

papercut87
20th April 2015, 14:21
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..


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?

papercut87
20th April 2015, 17:13
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/57849-drag-and-drop-drag-item-from-QListWidget-to-desktop-or-any-open-directory where you solved this problem.

So, thanks so much again!