4

我正在尝试运行此代码:

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

但我收到此错误:

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

2 回答 2

4

你可以尝试这样的事情:

QScreen *screen = QGuiApplication::primaryScreen();
if (screen)
{
    QPixmap ss = screen->grabWindow((WId) FindWindow(NULL, L"Blacklight Retribution"));
}
于 2015-03-28T16:57:31.427 回答
2

Qt 5 更新了 Screenshot 示例,shootScreen 函数如下所示:

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

    originalPixmap = screen->grabWindow(0);
    updateScreenshotLabel();
}
于 2018-01-23T12:19:49.480 回答