How to manage clipboard to check for url using mime-types

  • I tried this, but it didn't work
    @ QClipboard *clipboard = QApplication::clipboard();

  • You have to use the correct methods, then it works:

    QClipboard clipboard = QApplication::clipboard();
    pMime = clipboard->mimeData();

        QUrl url;
        foreach(url, pMime->urls())
            // do something with the url


    see the "docs of QMimeData":

  • Why to use foreach, as clipboard can contain only one string (url) at any instant

  • if you select several files for example, you can have several urls in the clipboard

  • I copied, then i executed the code:
    @QClipboard clipboard = QApplication::clipboard();
    const QMimeData
    pMime = clipboard->mimeData();


    surl is still empty.

  • if you copy text, then perhaps pMime->hasUrls returns false?
    Did you try hasText?

  • In that case it would copy any text string, strings which are not urls too. It defeats the purpose of using mime data in that case.
    I actually wish to monitor http/ftp download urls copied to clip board, and later on filter out urls of webpages

  • 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":

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.