In windows this is very simple:
auto pixmap = qApp->screens().at(0)->grabWindow(QDesktopWidget().winId());
But grabWindow isn't working on linux. I try something like:
QScreen *screen = QGuiApplication::primaryScreen();
auto pixmap = QPixmap::grabWindow(0);
but with no good result.