gpt4 book ai didi

c++ - 如何在 Ubuntu Qt 中获取事件窗口标题?

转载 作者:行者123 更新时间:2023-11-28 04:46:08 26 4
gpt4 key购买 nike

我正在使用下面的 win API 代码来捕获 Windows 桌面中的事件工作窗口标题。对于这个实现,Ubuntu 平台的 Qt 有任何替代方案吗?

QString getActiveWndTitle()
{
char buff[256];
HWND hwnd = GetForegroundWindow();
GetWindowText(hwnd, (LPWSTR) buff, 254);
QString title = QString::fromWCharArray((const wchar_t *)buff);
return title;
}

最佳答案

如果想获取Qt应用程序事件窗口的标题,可以使用

QApplication::activeWindow()->windowTitle();

如果没有,您可以使用 QProcess 运行 Ubuntu 命令。这是 xdotool 或(如果您不想安装任何东西)此命令:

xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) WM_NAME | awk -F '"' '{print $2}' 

关于c++ - 如何在 Ubuntu Qt 中获取事件窗口标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49233573/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com