PDA

View Full Version : [solved]drag a picture to a different application



Qiieha
20th June 2011, 09:15
hi
I want to drag a picture to a different application (f.e. gimp). It works fine with that code:


QMimeData* mimedata = new QMimeData;
mimedata->setImageData(QImage("/home/user/picture.jpeg"));
QDrag *drag = new QDrag(this);
drag->setMimeData(mimedata);
QPixmap& pic = *picture;
drag->setPixmap(pic);
drag->exec(Qt::MoveAction);

But there is a problem. The picture is in the application, but it doesn't point to the picture on the file system. It's just a paste command. Does anybody know what I have to do?

thanks

Rachol
20th June 2011, 09:23
Perhaps you should try to pass the file name, not the image itself.

stampede
20th June 2011, 09:23
Try adding:


mimedata->setUrls( QList<QUrl>() << QUrl::fromLocalFile( "/home/user/picture.jpeg") );

Qiieha
20th June 2011, 09:30
thank u guys!! :)


mimedata->setUrls( QList<QUrl>() << QUrl::fromLocalFile( "/home/user/picture.jpeg") );

works perfect! great!