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 drop an image onto google lens?
QtWS25 Last Chance

How to drop an image onto google lens?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 949 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.
  • B Offline
    B Offline
    BwvB
    wrote on 18 Jun 2023, 12:40 last edited by
    #1

    Hi,

    I would like to be able drag an image from my Qt-application (C++) onto a google lens search in a browser (firefox). Is there a way to do this?

    Regards,
    Bertwim

    S 1 Reply Last reply 18 Jun 2023, 19:59
    0
    • S SGaist
      19 Jun 2023, 20:07

      There's no need to allocate urls on the heap. I would also use QUrl::fromLocalFile to build the URL properly.

      B Offline
      B Offline
      BwvB
      wrote on 19 Jun 2023, 20:14 last edited by
      #7

      @SGaist Yes, the QUrl::fromLocalFile(...) is doing the trick! Thanks for the suggestion!

      S 1 Reply Last reply 19 Jun 2023, 20:16
      0
      • B BwvB
        18 Jun 2023, 12:40

        Hi,

        I would like to be able drag an image from my Qt-application (C++) onto a google lens search in a browser (firefox). Is there a way to do this?

        Regards,
        Bertwim

        S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 18 Jun 2023, 19:59 last edited by
        #2

        Hi,

        The Drag and Drop chapter is a good starting point.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        B 1 Reply Last reply 19 Jun 2023, 17:27
        1
        • S SGaist
          18 Jun 2023, 19:59

          Hi,

          The Drag and Drop chapter is a good starting point.

          B Offline
          B Offline
          BwvB
          wrote on 19 Jun 2023, 17:27 last edited by
          #3

          @SGaist Sure, it is. That's what I did. When I drag and drop (in my case: a url to an image) in my own application (from a treeview to a QMDIArea) it works perfectly alright. But when dragged the same object to Google Lens, nothing happens.
          In the mean time, I found that when I drag a file from a Qt FileSelectorbox to Google lens, the behaviour is as expected. So at least now I know that there is a way to do it. I;m trying to find out what the FileSelectorBox is doing differently...
          If you have any hint, that would be welcome.
          Regards,
          Bertwim

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 19 Jun 2023, 18:17 last edited by
            #4

            It's likely related to the mime type. Which one are you using ? Which one is that dialog using ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            B 1 Reply Last reply 19 Jun 2023, 19:59
            0
            • S SGaist
              19 Jun 2023, 18:17

              It's likely related to the mime type. Which one are you using ? Which one is that dialog using ?

              B Offline
              B Offline
              BwvB
              wrote on 19 Jun 2023, 19:59 last edited by
              #5

              @SGaist
              I have minimised the problem to the following.

              • I create a QUrl with the absolute path to some jpg image.
              • with this QUrl, I create and initialise a QMimeData object, using mimedata->setUrls(). . (code below)
              • dragging this to Google Lens (Firefox browser) gives the error message: "Can't use this link. Check that your link starts with 'http://' or 'https://' to try again".
              • the above error does not seam unreasonable, somehow it misses the point that it needs to upload the local file. but what can I do?
              • When I open a QFileSelector in the directory of the image, so that I see the image file in the directory list, I can drag the very same file to Google Lens, and it works! I can't figure out what the QFileSelector is doing differently. If I drag the latter to e.g. the command line, it just shows the text representation of the full path.

              In the override of mouseMoveEvent of my subclass of QTreeView I have the following code to create a drag object:

              QMimeData* mimeData = new QMimeData; 
              auto urls = new QList<QUrl>;
              urls->append( QUrl( "/abspath../image.jpg" ) );
              mimeData->setUrls( *urllist );
              
              // Initialise a new drag object and proceed.
              QDrag* drag = new QDrag( this );
              drag->setMimeData( mimeData ); 
              
              auto dropAction = drag->exec( Qt::CopyAction | Qt::MoveAction );
              
              me->accept();
              
              S 1 Reply Last reply 19 Jun 2023, 20:07
              0
              • B BwvB
                19 Jun 2023, 19:59

                @SGaist
                I have minimised the problem to the following.

                • I create a QUrl with the absolute path to some jpg image.
                • with this QUrl, I create and initialise a QMimeData object, using mimedata->setUrls(). . (code below)
                • dragging this to Google Lens (Firefox browser) gives the error message: "Can't use this link. Check that your link starts with 'http://' or 'https://' to try again".
                • the above error does not seam unreasonable, somehow it misses the point that it needs to upload the local file. but what can I do?
                • When I open a QFileSelector in the directory of the image, so that I see the image file in the directory list, I can drag the very same file to Google Lens, and it works! I can't figure out what the QFileSelector is doing differently. If I drag the latter to e.g. the command line, it just shows the text representation of the full path.

                In the override of mouseMoveEvent of my subclass of QTreeView I have the following code to create a drag object:

                QMimeData* mimeData = new QMimeData; 
                auto urls = new QList<QUrl>;
                urls->append( QUrl( "/abspath../image.jpg" ) );
                mimeData->setUrls( *urllist );
                
                // Initialise a new drag object and proceed.
                QDrag* drag = new QDrag( this );
                drag->setMimeData( mimeData ); 
                
                auto dropAction = drag->exec( Qt::CopyAction | Qt::MoveAction );
                
                me->accept();
                
                S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 19 Jun 2023, 20:07 last edited by
                #6

                There's no need to allocate urls on the heap. I would also use QUrl::fromLocalFile to build the URL properly.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                B 1 Reply Last reply 19 Jun 2023, 20:14
                0
                • S SGaist
                  19 Jun 2023, 20:07

                  There's no need to allocate urls on the heap. I would also use QUrl::fromLocalFile to build the URL properly.

                  B Offline
                  B Offline
                  BwvB
                  wrote on 19 Jun 2023, 20:14 last edited by
                  #7

                  @SGaist Yes, the QUrl::fromLocalFile(...) is doing the trick! Thanks for the suggestion!

                  S 1 Reply Last reply 19 Jun 2023, 20:16
                  0
                  • B BwvB
                    19 Jun 2023, 20:14

                    @SGaist Yes, the QUrl::fromLocalFile(...) is doing the trick! Thanks for the suggestion!

                    S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 19 Jun 2023, 20:16 last edited by
                    #8

                    Great !

                    Since you have it working now, please mark the thread as solved using the "Topic Tools" button or the three dotted menu beside the answer you deem correct so that other forum users may know a solution has been found :-)

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • B BwvB has marked this topic as solved on 19 Jun 2023, 20:17

                    7/8

                    19 Jun 2023, 20:14

                    • Login

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