PDA

View Full Version : QClipboard and Windows



GodOfWar
20th July 2008, 15:25
Hi all!
I must prepare an application for Windows for copying files, it's some kind of "Advanced Paste".
It should read a list of filepaths from the system clipboard (this filepaths are already in the clipboard using the windows buit-in Edit->Copy function from the file manager) and make a copy of those files using a series of rules that the user can specify.
On linux it works perfectly, while in windows I have some problem. In linux when you issue the "Copy" command, you will find a simple list of paths in the clipboard. In windows I can't figure out what format is used, so I cannot identify the selected files.
This is the section of code which takes the filepaths from the clipboard:


...
QClipboard *clipboard=qApp->clipboard();
qDebug()<<"The system clipboard contains:\n" <<clipboard->text();
QString clipboard_text=clipboard->text();
QStringList file_list=clipboard_text.split('\n',QString::SkipE mptyParts);
...


Under linux it works and gives me the content of the clipboard, on windows it says the clipboard is empty.
Anyone can help?

jpn
20th July 2008, 20:39
See QClipboard::mimeData() and QMimeData::urls().

GodOfWar
20th July 2008, 23:49
See QClipboard::mimeData() and QMimeData::urls().

I already tried it.
The urls() doesn't return anything because the clipboard format used by Windows for filepaths isn't standard (I guess you didn't expect that, don't you?:p). Windows uses some shitty format (application/x-qt-windows-mime;value="Shell IDList Array or something like that) and I don't understand how to use QWindowsMime:crying: which should override the problem. Now I'm trying to use directly the windows API to obtain a dump of the data saved in the clipboard and then I plan to extrapolate the filepaths from there. It's just tedious.
Anyone got better ideas?

jpn
21st July 2008, 07:14
At least the drag and drop data from Windows Explorer (http://wiki.qtcentre.org/index.php?title=Drop_files_and_images_on_QTextEdit ) contains "text/uri-list". I'd expected the clipboard data to follow same convention.

aamer4yu
21st July 2008, 08:32
I dont think you are evaluating the mime data properly.
I checked the Drop Site example in Qt Demo. When I drag and drop multiple files, I get
Format -
application/x-qt-windows-mime;value="Shell IDList Array"
...
...
text/uri-list


In the text/uri-list , in the contents part I see the list of file names.

Please refer to the Drop Site example and see urself. May be clipboard does same thing. You need to iterate over the mime data like in the example.

GodOfWar
21st July 2008, 09:05
Ok I will give a try with that tutorial.
However if I try to take "text/uri-list" data from the MimeData it returns empty string (even though I already selected and "copied" some files).

EDIT:
OMG I think I found the error. You were right, using urls() function return a url list of the selected files. The problem seems to be about some configuration option in the project file. I forgot to specifiy the qmakespec and the TARGET variable so basically I executed the same program over and over without modifying anything:eek:.
This brings me to another question: Is there a GOOD Windows IDE compatible with QT, which supports project file creation and customization, and project building and debugging??
I tried CodeBlocks but it doesn't work that well (I can't start the debug).