Results 1 to 2 of 2

Thread: Getting image directly with runJavaScript

  1. #1
    Join Date
    Apr 2009
    Posts
    29
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Getting image directly with runJavaScript

    Hi there,

    Firstly some source code:

    Qt Code:
    1. QWebEngineView *m_Browser = new QWebEngineView(this);
    2.  
    3. m_Browser->setUrl("http://www.nytimes.com/");
    4.  
    5. m_Browser->page()->runJavaScript("document.querySelector('img').src;", [&] (const QVariant &result) {
    6. qDebug()<< result << result.toByteArray();
    7. });
    To copy to clipboard, switch view to plain text mode 

    With runJavaScript I select the first found image and .src delivers the src tag of the image (e.g. https://static01.nyt.com/images/.....375.jpg). This works very well but if I remove the src tag I get the img object itself.
    Qt Code:
    1. m_Browser->page()->runJavaScript("document.querySelector('img');", [&] (const QVariant &result) {
    2. qDebug()<< result << result.toByteArray();
    To copy to clipboard, switch view to plain text mode 

    QDebug says I get "QVariant(QVariantMap, QMap())", it is possible to convert this response to put it in a QPixmap? I can use the src of the image to load the image but when it is possible to obtain the image directly that would be nice.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Getting image directly with runJavaScript

    I am not sure, but wouldn't you get the tag object if you don't specify the attribute?

    Does the img tag even have the notion of image data that a script could access?

    Cheers,
    _

Similar Threads

  1. Set QHash and QMap value directly
    By wirasto in forum Qt Programming
    Replies: 2
    Last Post: 17th December 2009, 20:21
  2. How do I paint directly ina QGraphcicsView?
    By extrakun in forum Qt Programming
    Replies: 3
    Last Post: 13th July 2009, 10:12
  3. Custom widget directly from .ui
    By blelump in forum Qt Tools
    Replies: 2
    Last Post: 2nd September 2008, 00:05
  4. Painting directly on the scene
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 27th September 2007, 14:55
  5. Can I directly draw my screen
    By iGoo in forum Qt Programming
    Replies: 1
    Last Post: 27th June 2006, 13:19

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.