screenshot
-
When I use the screen>grabWindow function to obtain screen pixel data, the program runs normally on Windows and Ubuntu desktop systems, but on embedded Linux systems, the function returns NULL. My code is as follows:
QScreen * screen=QGuiApplication:: primaryScreen();
QPixmap pixmap=screen ->grabWindow (0)// Return null value
Pixmap. save ("screenshot. png");
-
There are several things that can go wrong here.
- The windowing platform might not allow an application to grab the screen, or might require some configuration external to the running application.
- The platform integration plugin might not implement QPlatformScreen::grabWindow(), causing the default do-nothing implementation to be used.
- An underlying driver might not implement the interface used by the platform plugin.
Make sure the relevant logging category is turned on, and look for output indicating a problem. If that doesn't show anything useful, it may be necessary to read through the platform plugin and verify the steps it takes.
For relatively easy testing, I would start by attempting to grab a window belonging to the application, and if that works, try a non-root window belonging to another application.
-
@jeremy_k Thank you for your reply. Let me describe my device environment information:
1.The version of Qt is 5.14.2
-
I use the eglfs platform plugin
-
The embedded device model I am using is RK3568
The image I built using the buildroot tool has a Linux kernel version of 4.19.206
I also have 2 questions to consult with you
1.What components of Qt do QScreen require to support? (Is it because I am missing the corresponding dynamic library component?)
- Do I need driver layer support to use the QScreen class? (Does the driver layer require corresponding famerbuffer read back support?)
-
-
-
@NanLi geometry dash world said in screenshot
:I made a mistake and the actual debugging was due to
QPixmap pixmap=screen ->grabWindow (0);
Pixmap. isNull()==true
So why does screen ->grabWindow (0) return null.
The reason screen->grabWindow(0) returns null is because it is trying to grab the contents of the entire screen, but the screen is not currently visible. This could be because the screen is not being displayed, or because it is being obscured by another window.
To fix this problem, you need to make sure that the screen is visible before you call grabWindow(). You can do this by calling show() on the screen object.
QScreen *screen = QGuiApplication::primaryScreen(); screen->show(); QPixmap pixmap = screen->grabWindow(0); if (pixmap.isNull()) { // Handle the error }
This code will first show the screen, and then it will grab the contents of the screen and store them in the pixmap variable. If the pixmap variable is null, then there was an error grabbing the screen contents.