Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED]Possible to transfer QML grabToImage result to C++?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Possible to transfer QML grabToImage result to C++?

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 2.3k 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.
  • O Offline
    O Offline
    ozzieve
    wrote on last edited by ozzieve
    #1

    Is there any way to transfer the image resulting from a grabToImage in QML to C++ please, rather than the saveToFile shown in the documentation?

    itemId.grabToImage(function(result) {
                        result.saveToFile("webpage.png");
                    });
    

    Below is the closest thing I've found to a solution, but I was wondering if there is a more mainstream/supported method?
    http://stackoverflow.com/questions/27429371/qml-and-c-image-interoperability

    Thank you.

    1 Reply Last reply
    0
    • O Offline
      O Offline
      ozzieve
      wrote on last edited by ozzieve
      #2

      Kept searching and found a solution to my own question:
      in MyClass.cpp:

      void MyClass::getGrabbedImage(QObject* i)
      {
          QQuickItemGrabResult *item = nullptr;
          item = qobject_cast<QQuickItemGrabResult*>(i);
          QImage qi(item->image());
      ...
      }
      

      ...in MyClass.h:

      Q_INVOKABLE void getGrabbedImage(QObject*);
      

      ..and in the .qml:

      itemId.grabToImage(function(result) {myClass.getGrabbedImage(result);});
      
      1 Reply Last reply
      1

      • Login

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