Capture screenshot not working (Qt 5.4) Linux Yocto
-
Hi,
I'm trying to capture a screenshot in PNG of my device that is running a custom Yocto linux build. When I run the application I get no value in the byteArray that contains the image. The code works fine on my Fedora Linux workstation.
The code is as follows:
@void Utils::GetScreenBase64String(QByteArray &bArray)
{QScreen *screen = QGuiApplication::primaryScreen(); if (screen) { QPixmap pixmap = QPixmap(); // Create a new pixmap pixmap = screen->grabWindow(0); // Grab the screenshot bArray.clear(); // Clear the byte array QBuffer buffer(&bArray); buffer.open(QIODevice::WriteOnly); pixmap.save(&buffer, "PNG"); buffer.close(); bArray = bArray.toBase64(); }
}@
I have also tried the following :
@void Utils::GetScreenBase64String(QByteArray &bArray)
{QScreen *screen = QGuiApplication::primaryScreen(); if (screen) { QWindow window; QPixmap pixmap = QPixmap(); // Create a new pixmap pixmap = screen->grabWindow(window.winId()); // Grab the screenshot bArray.clear(); // Clear the byte array QBuffer buffer(&bArray); buffer.open(QIODevice::WriteOnly); pixmap.save(&buffer, "PNG"); buffer.close(); bArray = bArray.toBase64(); }
}@
bArray in both cases is returned empty. Not sure if I am missing some kernel library. Any help would be appreciated.
Thanks!
-
Thanks for replying to this. I added the QQuickWindow module to the file and to the .pro (quick) file. But I now run into the following issue on compile time:
/home/gmahan/Qt5.4.0/5.4/gcc_64/include/QtGui/qopengl.h:122: error: GL/gl.h: No such file or directory
include <GL/gl.h>
^
Not sure what's causing this. Sorry, I'm relatively new to Qt.
-
Hmm you are missing OpenGL support. Then your apps are QWidget-based, I guess? In that case try something like http://doc-snapshot.qt-project.org/qt5-5.4/qwidget.html#render
-
I changed the function to use QWidget.render(), but all I get is a blank screen as the image.
@void Utils::GetScreenBase64String(QByteArray &bArray, QWidget *widget)
{QScreen *screen = QGuiApplication::primaryScreen(); if (screen) { QPixmap pixmap(widget->size()); // Create a new pixmap widget->render(&pixmap); //pixmap = screen->grabWindow(WindowId::GetCurrentWinId()); // Grab the screenshot bArray.clear(); // Clear the byte array QBuffer buffer(&bArray); buffer.open(QIODevice::WriteOnly); pixmap.save(&buffer, "PNG"); buffer.close(); bArray = bArray.toBase64(); }
}
@