我正在尝试运行此代码:
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
我正在尝试运行此代码:
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
你可以尝试这样的事情:
QScreen *screen = QGuiApplication::primaryScreen();
if (screen)
{
QPixmap ss = screen->grabWindow((WId) FindWindow(NULL, L"Blacklight Retribution"));
}
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();
}