0% found this document useful (0 votes)
41 views

C Plus - Add - Qt-Embedded - Capturing Screen With QPixmap

The document describes how to capture screenshots from a Qt/Embedded application running on embedded Linux. It uses a QTimer to periodically check for a file, and if it exists, it takes a screenshot and saves it with the filename from the file. This allows remotely triggering screenshot captures from a serial console.

Uploaded by

Binod Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

C Plus - Add - Qt-Embedded - Capturing Screen With QPixmap

The document describes how to capture screenshots from a Qt/Embedded application running on embedded Linux. It uses a QTimer to periodically check for a file, and if it exists, it takes a screenshot and saves it with the filename from the file. This allows remotely triggering screenshot captures from a serial console.

Uploaded by

Binod Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

5/1/2020 C Plus / Add: Qt-Embedded: Capturing screen with QPixmap

More

C Plus / Add
Embedded systems programming / C, C++

Saturday, July 4, 2009 Blog Archive

Qt-Embedded: Capturing screen with QPixmap ► 2013 (3)


► 2012 (3)
I've been working on a product manual lately. I needed to include several LCD screenshots into it so I tried to come up with
an easy way to capture snapshots from our Qt/Embedded app. ► 2011 (4)
Qt/Embedded provides a nice method to save window/framebuffer contents directly to an image file. However, I wanted ► 2010 (3)
to send the 'take-snapshot' command from a tty console (telnet/serial/etc) since there weren't any other buttons on the
system to trigger that. ▼ 2009 (14)
A QTimer is set up. Periodically it checks the file /tmp/doCapture. If it exists a snapshot is taken and an image file is ► December (1)
saved. Its filename is taken from the contents of /tmp/doCapture. After saving the image /tmp/doCapture is deleted.
► August (1)
Here is the code, which should be placed in the main window, whose width and height cover the whole screen:
▼ July (1)
Qt-Embedded:
Capturing
mainWindow::mainWindow() screen with
{ QPixmap
// captureTimer should be declared in mainWindow's class definition
captureTimer = new QTimer(this); ► May (1)
connect( captureTimer, SIGNAL(timeout()), this, SLOT(captureTimerEvent()) );
► April (2)

captureTimer->start(1000); //check interval ► March (3)


} ► February (2)

void mainWindow::captureTimerEvent() ► January (3)


{
QString tmpFile = QString("/tmp/doCapture"); ► 2008 (11)

if ( !QFile::exists(tmpFile) )
return;
About Me
QFile f(tmpFile); CjB
if ( !f.open( QIODevice::ReadWrite ) )
return; Carlos Becker
http://carlosbecker.com.ar
char buf[200]; View my complete profile
if ( f.readLine( buf, sizeof(buf) - 4 ) == -1 )
return;
My Blog List
buf[strlen(buf)-1] = '\0'; //remove \n created by 'echo'-- not safe!
C + o − Programación en
strcat( buf, ".png" ); C/C++
La Novedad
//capture 5 weeks ago
QPixmap p = QPixmap::grabWindow( this->winId() );
Notas de código fuente
if ( p.save( buf ) ) Memoize in Java with
printf("------- GRAB OK\n"); Guava
else 3 years ago
printf("------- ERR GRAB!\n");
puedesverlo
/* delete file */ No Class - Motörhead
f.remove(); 4 years ago
}
Si no sucede, no pasa
VALSE
5 years ago
This way, all I have to do to take a snapshot is to write:

echo pngfilename > /tmp/doCapture Stats

Posted by CjB at 1:20 AM


Labels: capture qt embedded

1 comment:

Héctor Rompato January 6, 2012 at 4:19 PM


Thanks, your solution (QPixmap p = QPixmap::grabWindow( this->winId() );) was helpfull to me.

Reply

cplusadd.blogspot.com/2009/07/qt-embedded-capturing-screen-with.html 1/2
5/1/2020 C Plus / Add: Qt-Embedded: Capturing screen with QPixmap

Enter your comment...

Comment as: Google Accou

Publish Preview

Newer Post Home Older Post

Subscribe to: Post Comments (Atom)

Awesome Inc. theme. Powered by Blogger.

cplusadd.blogspot.com/2009/07/qt-embedded-capturing-screen-with.html 2/2

You might also like