PDA

View Full Version : QPixmap::grabWindow does not work on some machines!



dima72
22nd July 2010, 13:30
Hello,
please help to solve, QPixmap::grabWindow does work on some XP machines and does not
work on the others,meaning i get empty bytes array


void screenshoot(QByteArray *p_bar)
{
QBuffer a_Buf;
QPixmap originalPixmap;
originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
originalPixmap.save(&a_Buf, "jpg");
*p_bar = a_Buf.buffer();
}

Qt4, MSVW 2008, WinXP, project compiled in release

thanks in advance,
dima

navi1084
22nd July 2010, 13:44
open the a_Buf using
a_Buf.open(QIODevice::WriteOnly);


QPixmap pixmap;
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format

dima72
23rd July 2010, 08:07
thank you navi

it is almost works.
If i use bmp format it works on that (specific) computer,
but if u use Jpeg
QBuffer a_Buf;
a_Buf.open(QIODevice::WriteOnly);
QPixmap lPixmap;
Pixmap = QPixmap::grabWindow(QApplication::desktop()->screen()->winId());
lPixmap.save(QApplication::applicationDirPath() + "\\screenshoot.jpeg", "jpeg");

there is no jpeg file produced as well as the gif

thanks in advance,
dima

dima72
26th July 2010, 07:02
i have found the problem,
it was plugins not setup on target machine.
looks like jpeg implemented in Qt as plugin.