Qt allows you to easily grab an screenshot and save it using grabWindow function implemented in QScreen. Here is how you can use it:
First of all decide on which part of the size and location of the screenshot you want to take. This means you have to create a QRect which has left, right, width and height values. Like this:
QRect crop_rect(x, y, w, h);
Next you can call grabWindow by providing this crop_rect to it to take an screenshot of any part of the screen.
QImage desk = qApp->screens().at(0)->grabWindow(
QDesktopWidget().winId(),
crop_rect.left(),
crop_rect.top(),
crop_rect.width(),
crop_rect.height()).toImage());
Please note that you can take an screenshot of the whole screen like this:
QImage desk = qApp->screens().at(0)->grabWindow(
QDesktopWidget().winId());