8

I am working on a Linux based embedded system. It uses Qt for windowing and there is no Xserver. My aim is to take screen shot of the screen.

I have tried using FBgrab. It failed since I don't have a /dev/fb0 since the frame buffer is not enabled in the kernel. We are running a Qt based application to show the UI on the screen (HDMI). I have also tried the screen shot application in the QT website which uses QPixmap and grab window. This also is a failure, since I can't run two QAppliction in the system since it affects the display.

Is there any other way to get the screen shot?

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
jsaji
  • 900
  • 1
  • 15
  • 31
  • @nos In the device, in /etc/directfbrc file we are giving an alternate graphics system(opengl) so Qt don't require /dev/fb0 – jsaji Feb 10 '14 at 12:57

2 Answers2

1

You can make your application take a screenshot of itself based on some event or command. You do this by grabbing the widget to a pixmap, and then saving this pixmap somewhere. For example:

QWidget *widget = QApplication::activeWindow();
QPixmap pixmap = QPixmap::grabWidget(widget);
pixmap.save(QString("/path/to/screenshot/screenshot.png"));
PurpleAlien
  • 886
  • 6
  • 7
  • Thank you for your quick replay. I have tried what you have said. The Code is **` #include int main(int argc, char **argv) { QApplication app(argc, argv); QWidget *widget = QApplication::activeWindow(); if (widget == NULL){ qWarning()<<"NULL"; return app.exec(); } QPixmap pixmap = widget->grab(); qWarning()<< pixmap.save(QString("./sample.png")); qWarning()<<"Saved"; return app.exec(); }`** Here I am not getting a widget. Its always NULL. – jsaji Feb 10 '14 at 12:59
  • Since I read in a comment above you're using GL, use QGLWidget::grabFrameBuffer(). – PurpleAlien Feb 10 '14 at 13:12
  • I want to take the screen shot from another application. ie The main application display images in the screen. I don't want to touch this application. From another application I want to save the screen UI to a file. Is that possible? This second application should not draw any thing in the screen... – jsaji Feb 10 '14 at 13:44
  • You probably want to use QPixmap::grabWindow from the other application, but I'm not 100% sure if this will work in your case. http://qt-project.org/doc/qt-4.8/qpixmap.html#grabWindow – PurpleAlien Feb 10 '14 at 14:17
  • I have tried that one. The code in the above comment. Am i doing any thing wrong in this.. – jsaji Feb 10 '14 at 15:21
  • Without seeing your code and what your system is doing, it's very hard to say why it doesn't work in your case... Anything more you can share? – PurpleAlien Feb 10 '14 at 16:00
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/47180/discussion-between-purplealien-and-griffin) – PurpleAlien Feb 10 '14 at 16:25
0

Assuming that your video software stack is not completely custom, your Linux video driver should be either a FBDEV one or a DRI one. To check this I would tell you to search for a /dev/fb0 file or a /dev/dri/ folder in your live box, but in an embedded device they could be easily renamed to whatever, so the only way to know is to check the video device driver sources (you will find them into drivers/video/ if they are FBDEV, or into /drivers/gpu/drm if they are DRI).

If they are FBDEV then /dev/fb0 should be there maybe with a different name. If they are DRI, you can still enable the DRM_FBDEV_EMULATION option when building the Linux kernel and have a FBDEV device node you can rely on with FBgrab.