I am using the following code to take screenshot in a Nokia device using Qt

QDesktopWidget *w = QApplication::desktop();
if (w)
        QRect r = w->screenGeometry();
        originalPixmap = QPixmap::grabWindow(w->winId(),0,0,r.width(), r.height());

originalPixmap.save(folder_path, format.toAscii().constData());

The code is working fine for portrait orientation. When I tilt the device to landscape, the captured image contains only half the width of the screen. Please help. Thanks in advance.