PDA

View Full Version : Copy-Paste files



Lele
3rd April 2008, 10:51
Hi all,
I would like to copy some files in to Windows clipboard (if it's the clipboard...) like
copying text with QClipboard. So then I can paste using normal Windows "Paste" command.
Is that possible?

thanks in advance

wysota
3rd April 2008, 11:01
Yes, just use an appropriate mime-type for your data. As far as I remember file paths can be encoded using text/url-list mime. But it's more likely that you want to store the object and not the file path itself...

Lele
3rd April 2008, 11:05
Yes, this is my case. I want to copy the entire file content like when someone does Copy and Paste from the file system. Can I do that from a QT Application?
thanks

wysota
3rd April 2008, 11:56
I already answered your question.

aamer4yu
3rd April 2008, 15:06
This (http://msdn2.microsoft.com/en-us/library/ms648709(VS.85).aspx) might help you :)

Lele
3rd April 2008, 16:11
thanks,
I thought there was a way using QT Clipboard, in a way that would be multiplatform.
I found
void QClipboard::setMimeData
but I don't really know how to use it.
Basically in my app I want to search for particular files and copy them in the clipboard(the entire file, not the file name). So then when I use "Paste" in the Operating system it will copy exactly those files.

bye

aamer4yu
3rd April 2008, 16:22
Just check the link I gave above.
And as others said, u will need to set the proper format and data in the clipboard. Browse a little. :)

wysota
3rd April 2008, 16:49
(the entire file, not the file name).
It's not the way it works. You copy file paths and then the target handles the paste (or drop as the mechanism is similar) and performs the copy. At least it works perfectly under KDE :) If you use local files or http/ftp Windows Explorer should handle it as well. As for other apps - it's up to them.

Lele
4th April 2008, 11:49
I tried with:



QMimeData* myFile= new QMimeData();
myFile->setData("text/uri-list", "file:///C:/test80.png");
clipboard->setMimeData(myFile);


But it doesn't seem to work.
Any idea?

thanks

wysota
4th April 2008, 12:45
Where did you try to paste the file?

Lele
4th April 2008, 13:21
in a normal window, but after my setData the "Paste" command was disabled.
I guess something wrong with the Mime format, I'll investigate more

wysota
4th April 2008, 14:15
"Normal window" meaning...? The desktop? Try copying from the desktop and pasting in a Qt app and see what mime it uses.