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?
Forum Updated to NodeBB v4.3 + New Features

How to drop an image onto google lens?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 1.0k Views 2 Watching
  • 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 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

    SGaistS 1 Reply Last reply
    0
    • SGaistS SGaist

      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 last edited by
      #7

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

      SGaistS 1 Reply Last reply
      0
      • B BwvB

        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

        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on 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
        1
        • SGaistS SGaist

          Hi,

          The Drag and Drop chapter is a good starting point.

          B Offline
          B Offline
          BwvB
          wrote on 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
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on 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
            0
            • SGaistS SGaist

              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 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();
              
              SGaistS 1 Reply Last reply
              0
              • B BwvB

                @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();
                
                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on 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
                0
                • SGaistS SGaist

                  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 last edited by
                  #7

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

                  SGaistS 1 Reply Last reply
                  0
                  • B BwvB

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

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 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

                    • Login

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