void screenShot(){QString image_str = "screenshot.png";QWidget *desktop_w = QApplication::desktop();WId w = desktop_w->winId();QScreen *screen = QApplication::primaryScreen();QPixmap pixmap = screen->grabWindow(w, 0, 0, desktop_w->width(), desktop_w->height());if(image_str .isNull()) return;if(pixmap.save(image_str , "PNG", 40) == false) { QFile(image_str ).remove(); }}
QPixmap pixmap; QByteArray bytes; QBuffer buffer(&bytes); buffer.open(QIODevice::WriteOnly); pixmap.save(&buffer, "PNG");