Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    2
    8
    2694
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      adnan last edited by

      I tried this, but it didn't work
      @ QClipboard *clipboard = QApplication::clipboard();
      if(clipboard->mimeData()->hasUrls())
      surl=clipboard->text(QClipboard::Clipboard);@

      1 Reply Last reply Reply Quote 0
      • G
        giesbert last edited by

        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

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply Reply Quote 0
        • A
          adnan last edited by

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

          1 Reply Last reply Reply Quote 0
          • G
            giesbert last edited by

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

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply Reply Quote 0
            • A
              adnan last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • G
                giesbert last edited by

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

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply Reply Quote 0
                • A
                  adnan last edited by

                  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

                  1 Reply Last reply Reply Quote 0
                  • G
                    giesbert last edited by

                    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

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post