How to take screenshot in QT 5.15.2 (qgroundcontrol app) for Android?
-
Qt Creator 7.0.2 running on Windows 10
QT 5.15.2
Android arm64-v8a
API 24: Android 7.0
QGroundControl Stable_V4.2Hi 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" errorAnd also I've tryed to implement the logic in the QML file, using "Window.contentItem.grabToImage(function(result)) "
but I had the same issue -
Hi and welcome to devnet,
For the storage error, are you properly requesting access to the storage for your application ?
-
@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