Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to take screenshot in QT 5.15.2 (qgroundcontrol app) for Android?
Forum Updated to NodeBB v4.3 + New Features

How to take screenshot in QT 5.15.2 (qgroundcontrol app) for Android?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 4 Posters 473 Views 1 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.
  • I Offline
    I Offline
    iu34
    wrote on last edited by iu34
    #1

    Qt Creator 7.0.2 running on Windows 10
    QT 5.15.2
    Android arm64-v8a
    API 24: Android 7.0
    QGroundControl Stable_V4.2

    Hi all,
    Does anybody has experience with implementing the feature of taking screenshots in QGC, in Android?
    I made it work for Windows, but when I build and ruin it on Android, it is creating an empty .png with 0 bytes, it is crashing at this line:
    QPixmap screenshot = screen->grabWindow(0);

    void VideoManager::takeScreenshot() {
        if (QMessageBox::question(nullptr, "Take Screenshot", "Do you want to take a screenshot?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
    
            QScreen *screen = QGuiApplication::primaryScreen();
            QPixmap screenshot = screen->grabWindow(0);
    
            QString fileName = "screenshot_" + QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss") + ".png";
    
            if (screenshot.save(fileName, "PNG")) {
                qDebug() << "Screenshot saved to:" << fileName;
            } else {
                qWarning() << "Failed to save screenshot!";
            }
        }
    }
    

    I also tryed this example, but still not working:
    https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/desktop/screenshot?h=6.6
    and it gave me "The immage could not be saved" error

    And also I've tryed to implement the logic in the QML file, using "Window.contentItem.grabToImage(function(result)) "
    but I had the same issue

    screenshot_notworkingAndroid.jpg

    screenshot_notworkin2.jpeg

    B Ronel_qtmasterR 2 Replies Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      For the storage error, are you properly requesting access to the storage for your application ?

      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
      • I iu34

        Qt Creator 7.0.2 running on Windows 10
        QT 5.15.2
        Android arm64-v8a
        API 24: Android 7.0
        QGroundControl Stable_V4.2

        Hi all,
        Does anybody has experience with implementing the feature of taking screenshots in QGC, in Android?
        I made it work for Windows, but when I build and ruin it on Android, it is creating an empty .png with 0 bytes, it is crashing at this line:
        QPixmap screenshot = screen->grabWindow(0);

        void VideoManager::takeScreenshot() {
            if (QMessageBox::question(nullptr, "Take Screenshot", "Do you want to take a screenshot?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
        
                QScreen *screen = QGuiApplication::primaryScreen();
                QPixmap screenshot = screen->grabWindow(0);
        
                QString fileName = "screenshot_" + QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss") + ".png";
        
                if (screenshot.save(fileName, "PNG")) {
                    qDebug() << "Screenshot saved to:" << fileName;
                } else {
                    qWarning() << "Failed to save screenshot!";
                }
            }
        }
        

        I also tryed this example, but still not working:
        https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/desktop/screenshot?h=6.6
        and it gave me "The immage could not be saved" error

        And also I've tryed to implement the logic in the QML file, using "Window.contentItem.grabToImage(function(result)) "
        but I had the same issue

        screenshot_notworkingAndroid.jpg

        screenshot_notworkin2.jpeg

        B Offline
        B Offline
        binru
        wrote on last edited by
        #3

        @iu34 why me Failed to save screenshot?

        1 Reply Last reply
        0
        • I iu34

          Qt Creator 7.0.2 running on Windows 10
          QT 5.15.2
          Android arm64-v8a
          API 24: Android 7.0
          QGroundControl Stable_V4.2

          Hi all,
          Does anybody has experience with implementing the feature of taking screenshots in QGC, in Android?
          I made it work for Windows, but when I build and ruin it on Android, it is creating an empty .png with 0 bytes, it is crashing at this line:
          QPixmap screenshot = screen->grabWindow(0);

          void VideoManager::takeScreenshot() {
              if (QMessageBox::question(nullptr, "Take Screenshot", "Do you want to take a screenshot?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
          
                  QScreen *screen = QGuiApplication::primaryScreen();
                  QPixmap screenshot = screen->grabWindow(0);
          
                  QString fileName = "screenshot_" + QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss") + ".png";
          
                  if (screenshot.save(fileName, "PNG")) {
                      qDebug() << "Screenshot saved to:" << fileName;
                  } else {
                      qWarning() << "Failed to save screenshot!";
                  }
              }
          }
          

          I also tryed this example, but still not working:
          https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/desktop/screenshot?h=6.6
          and it gave me "The immage could not be saved" error

          And also I've tryed to implement the logic in the QML file, using "Window.contentItem.grabToImage(function(result)) "
          but I had the same issue

          screenshot_notworkingAndroid.jpg

          screenshot_notworkin2.jpeg

          Ronel_qtmasterR Offline
          Ronel_qtmasterR Offline
          Ronel_qtmaster
          wrote on last edited by
          #4

          @iu34 did you try this?
          QPixmap map = QPixmap::grabWindow(QApplication::desktop()->winId(), this->x(), this->y(), width(), height());

          i know it might be deprecated but the fact that your screenshot is 0 sized is weird.
          After Installing your app make sure to enable storage permission.Hope it helps

          1 Reply Last reply
          0

          • Login

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