How to drop an image onto google lens?
-
There's no need to allocate
urls
on the heap. I would also use QUrl::fromLocalFile to build the URL properly. -
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,
BertwimHi,
The Drag and Drop chapter is a good starting point.
-
Hi,
The Drag and Drop chapter is a good starting point.
@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 -
It's likely related to the mime type. Which one are you using ? Which one is that dialog using ?
-
It's likely related to the mime type. Which one are you using ? Which one is that dialog using ?
@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();
-
@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();
There's no need to allocate
urls
on the heap. I would also use QUrl::fromLocalFile to build the URL properly. -
There's no need to allocate
urls
on the heap. I would also use QUrl::fromLocalFile to build the URL properly. -
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 :-)
-