试图获取窗口的屏幕截图

时间:2013-04-12 03:06:10

标签: qt

我正在尝试运行此代码:

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

2 个答案:

答案 0 :(得分:3)

您可以尝试这样的事情:

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

答案 1 :(得分:0)

Qt 5已更新截图示例和shootScreen功能如下所示:

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

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