Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to manage clipboard to check for url using mime-types

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

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 3.1k Views
  • 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 Offline
    A Offline
    adnan
    wrote on last edited by
    #1

    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
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      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
      0
      • A Offline
        A Offline
        adnan
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          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
          0
          • A Offline
            A Offline
            adnan
            wrote on last edited by
            #5

            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
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              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
              0
              • A Offline
                A Offline
                adnan
                wrote on last edited by
                #7

                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
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #8

                  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
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved