user2272792
user2272792

Reputation: 51

Trying to get screenshot of a window

I'm trying to run this code:

QPixmap ss = QScreen::grabWindow((WId) FindWindow(NULL, L"Blacklight Retribution"));
ss.save("haystack.png", "png");

but I am getting this error:

error: C2352: 'QScreen::grabWindow' : illegal call of non-static member function

Upvotes: 4

Views: 5171

Answers (2)

Tony
Tony

Reputation: 1611

Qt 5 has updated Screenshot example and shootScreen function looks as the following:

void Screenshot::shootScreen()
{
    QScreen *screen = QGuiApplication::primaryScreen();
    if (const QWindow *window = windowHandle())
        screen = window->screen();
    if (!screen)
        return;

    originalPixmap = screen->grabWindow(0);
    updateScreenshotLabel();
}

Upvotes: 2

jtomaszk
jtomaszk

Reputation: 11161

You could try something like this:

QScreen *screen = QGuiApplication::primaryScreen();
if (screen)
{
    QPixmap ss = screen->grabWindow((WId) FindWindow(NULL, L"Blacklight Retribution"));
}

Upvotes: 4

Related Questions