How to manage clipboard to check for url using mime-types
-
You have to use the correct methods, then it works:
@
QClipboard clipboard = QApplication::clipboard();
QMimeData pMime = clipboard->mimeData();if(pMime->hasUrls()) { QUrl url; foreach(url, pMime->urls()) { // do something with the url } }
@
see the "docs of QMimeData":http://qt-project.org/doc/qt-4.8/qmimedata.html#details
-
I copied http://qt-project.org, then i executed the code:
@QClipboard clipboard = QApplication::clipboard();
const QMimeData pMime = clipboard->mimeData();if(pMime->hasUrls()) { surl=clipboard->text(QClipboard::Clipboard); }@
surl is still empty.
-
The problem here is that it depends on the application thatcopies the text ton the clipborad which type the clipboard data has. If it copies it as text, you can only read it as text. But you could use QUrl to verify, whether it is a url.
To check the mime data, you could use "one of the drag/drop examples":http://qt-project.org/doc/qt-4.8/draganddrop-dropsite.html